Model-level "validators" are for automatic validation when there are attempts to save values to the object's fields. Annotations that start with @ followed by an ID (validator name), and that are used on object attributes are validator annotations. See "Creating Complex Validators" below on how to define the validators. The ID value must match the name of a defined validator.
object Person
{
@FirstnameValidator("validr.msg.fname")
string fname;
@SurnameValidator("validr.msg.sname")
string sname;
}
Creating Complex Validators
In a .mez file, under ./model/, use the validator keyword followed by a validator name, followed by a block containing atomic validators:
Checks that the value is not less than the supplied minimum value.
maxval(6.18);
Checks that the values is not greater than the supplied maximum value.
minlen(2);
Checks that a string value does not have less characters than the supplied minimum value.
maxlen(255);
Checks that a string value does not have more characters than the supplied maximum value.
Regex Validation in Presenter Units
Whereas the above validators are entered into the model object for automatic validation upon save attempts, any value in a string variable can be compared to a specified regular expression for manual validation with bool b = String:regexMatch(s, r).
if (String:regexMatch("27000111abc","^27[0-9]{9,}$") == false) {
Mez:alertError("alert.invalid.phonenum");
}
Add Comment