Module function reference
input_validate
A reference entry for input_validate
input_validate(fn f, string failure_message[, number max_times]) ⇒ mixed
Reads input until the supplied function accepts it, optionally stopping after a maximum number of attempts.
Examples
The validator can use a named function and its handle:
YASS
function check($x) if ($x == "password") return true else return false end if end function $value = Validation::input_validate( handle_of(check), "Incorrect password." ) print($value)
An inline validator can check that a number is within a range:
YASS
$number = Validation::input_validate( function($x) $x = value($x) return $x > 10 and $x < 100 end function, "Number must be between 10 and 100." ) print($number)
A regular-expression validator can check a capitalised name:
YASS
$name = Validation::input_validate( function($x) return string_matches($x, "[A-Z][a-z]+") end function, "Name must start with a capital letter.", 3 ) print($name)