View Source Draft.Validator.Format (Draft v1.0.2)
Ensure a value matches a regular expression.
options
Options
:with
: The regular expression.:message
: Optional. A custom error message. May be in EEx format and use the fields described in "Custom Error Messages," below.
The regular expression can be provided in place of the keyword list if no other options are needed.
examples
Examples
iex> Draft.Validator.Format.validate("foo", ~r/^f/)
{:ok, "foo"}
iex> Draft.Validator.Format.validate("foo", ~r/o{3,}/)
{:error, "must have the correct format"}
iex> Draft.Validator.Format.validate("foo", [with: ~r/^f/])
{:ok, "foo"}
iex> Draft.Validator.Format.validate("bar", [with: ~r/^f/, message: "must start with an f"])
{:error, "must start with an f"}
iex> Draft.Validator.Format.validate("", [with: ~r/^f/, allow_blank: true])
{:ok, ""}
iex> Draft.Validator.Format.validate(nil, [with: ~r/^f/, allow_nil: true])
{:ok, nil}
Link to this section Summary
Functions
Callback implementation for c:Draft.Validator.Behaviour.validate/2
.
Callback implementation for c:Draft.Validator.Behaviour.validate/3
.
Link to this section Functions
Callback implementation for c:Draft.Validator.Behaviour.validate/2
.
Callback implementation for c:Draft.Validator.Behaviour.validate/3
.