Validation
Functions
Returns the first error for the given key in the given errors.
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!"})
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!"})
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!"})
Returns the given error if the given string is not a number.
Validation.isNumber("asd", {"age", "Age is not a number!"}) ==
Maybe::Just({"age", "Age is not a number!"})
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!"})
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!"})
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."))