Try Install Learn Blog API Packages GitHub
Pages
core

Search
Entities

Validation

Functions

getFirstError
(
errors
:
Map(String, Array(String))
key
:
String
)
:
Maybe(String)

Returns the first error for the given key in the given errors.

hasExactNumberOfCharacters
(
value
:
String
size
:
Number
error
:
Tuple(String, String)
)
:
Maybe(Tuple(String, String))

Returns the given error if the given string is does not have the exact number of characters.

Validation.hasExactNumberOfCharacters(
  "",
  5,
  {"zip", "Zip code does is not 5 characters!"}) ==
    Maybe::Just({"zip", "Zip code does is not 5 characters!"})
hasMinimumNumberOfCharacters
(
value
:
String
size
:
Number
error
:
Tuple(String, String)
)
:
Maybe(Tuple(String, String))

Returns the given error if the given string does not have at least the given number of characters.

Validation.hasMinimumNumberOfCharacters(
  "",
  5,
  {"zip", "Zip code does is not 5 characters or more!"}) ==
    Maybe::Just({"zip", "Zip code does is not 5 characters or more!"})
isDigits
(
value
:
String
error
:
Tuple(String, String)
)
:
Maybe(Tuple(String, String))

Returns the given error if the given string does not consist of just digits.

Validation.isDigits("1234x", {"zip", "Zip code is not just digits!"}) ==
  Maybe::Just({"zip", "Zip code is not just digits!"})
isNotBlank
(
value
:
String
error
:
Tuple(String, String)
)
:
Maybe(Tuple(String, String))

Returns the given error when the given string is blank (contains only whitespace).

Validation.isNotBlank("", {"name", "Name is empty!"}) ==
  Maybe::Just({"name", "Name is empty!"})
isNumber
(
value
:
String
error
:
Tuple(String, String)
)
:
Maybe(Tuple(String, String))

Returns the given error if the given string is not a number.

Validation.isNumber("foo", {"multiplicand", "Multiplicand is not a number!"}) ==
  Maybe::Just({"multiplicand", "Multiplicand is not a number!"})
isSame
(
value
:
a
value2
:
a
error
:
Tuple(String, String)
)
:
Maybe(Tuple(String, String))

Returns the given error if the two given values are not the same.

Validation.isSame(
  "password",
  "confirmation",
  {"confirmation", "Confirmation is not the same!"}) ==
    Maybe::Just({"confirmation", "Confirmation is not the same!"})
isValidEmail
(
value
:
String
error
:
Tuple(String, String)
)
:
Maybe(Tuple(String, String))

Returns the given error if the given string is not an email address.

Validation.isValidEmail(
  "test",
  {"email", "Email is not a valid email address!"}) ==
    Maybe::Just({"email", "Email is not a valid email address!"})
merge
(
errors
:
Array(Maybe(Tuple(String, String)))
)
:
Map(String, Array(String))

Merges the result of many validations into a Map(String, Array(String)).

Validation.merge([
  Validation.isNotBlank("", {"firstName", "Please enter the first name."}),
  Validation.isNotBlank("", {"message", "Please enter the message."}),
]) == (Map.empty()
  |> Map.set("firstName", "Please enter the first name.")
  |> Map.set("message", "Please enter the message."))