dataval/validator
Values
pub fn float_max(
max: Float,
) -> fn(Float) -> Result(Float, List(field.FieldError(custom)))
Validate that value <= max
pub fn float_min(
min: Float,
) -> fn(Float) -> Result(Float, List(field.FieldError(custom)))
Validate that value >= min
pub fn int_max(
max: Int,
) -> fn(Int) -> Result(Int, List(field.FieldError(custom)))
Validate that value <= max
pub fn int_min(
min: Int,
) -> fn(Int) -> Result(Int, List(field.FieldError(custom)))
Validate that value >= min
pub fn not_empty(
value: String,
) -> Result(String, List(field.FieldError(custom)))
Validate that the value is not an empty string
Same as required()
pub fn regexp_check(
re: regexp.Regexp,
) -> fn(String) -> Result(String, List(field.FieldError(custom)))
Validate that the passed regexp has a match in the value.
It uses regexp.check(re, value)
Example
let assert Ok(alphanum_regexp) = regexp.from_string("^[a-zA-Z0-9]+$")
let my_input =
field.new("my_input")
|> field.add_validator(validator.regexp_check(alphanum_regexp))
let assert Error([field.MustMatchRegexp]) = field.validate(my_input, "abc$def")
let assert Ok("abc123") = field.validate(my_input, "abc123")
pub fn required(
value: String,
) -> Result(String, List(field.FieldError(custom)))
Validate that the value is not an empty string
Same as not_empty()
pub fn str_max(
max: Int,
) -> fn(String) -> Result(String, List(field.FieldError(custom)))
Validate that string.length(value) <= max
pub fn str_min(
min: Int,
) -> fn(String) -> Result(String, List(field.FieldError(custom)))
Validate that string.length(value) >= min