Versions Compared
Version | Old Version 10 | New Version 11 |
---|---|---|
Changes made by | Former user |
Former user |
Saved on |
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Table of Contents |
---|
Available Atomic Validators
These are the building blocks used for creating complex validators:
validator/usage | description |
---|---|
notnull(); | Check that the attribute is not null. This validator does not take any arguments. |
regex("^[A-Z a-z]*$"); | Checks that the value conforms to a regular expression. Allows upper & lower case and spaces. |
regex("^[A-Za-z0-9 ]*$"); | Another regex example. Alphanumeric with spaces. |
regex("^27[0-9]*$"); | Another regex example. Number starting with 27. |
regex("\b[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+[.][A-Za-z]{2,4}\b"); | Another regex example. Email. |
minval(3.145); | 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. |
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:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
validator FirstnameValidator { notnull; minlen(2); maxlen(250); } validator AgeValidator { minval(0); } validator CTMetroPhoneNumber { notnull(); regex("021-[7..9]{7}"); } |
Annotating Object Attributes with Validators
Annotations that start with @
followed by an ID (validator name), and that are used on object attributes are validator annotations. The ID value must be the same as any validator that is defined in the application:
Code Block | ||
---|---|---|
| ||
object Person { @FirstnameValidator("validr.msg.fname") string fname; @SurnameValidator("validr.msg.sname") string sname; } |
Additional Mentions and References
- Section Ensuring Valid Data in the tutorial's Lesson 3
- Atomic Validators and Object Attribute Annotations in the Quick Reference
Excerpt | ||
---|---|---|
| ||
notnull() etc. | validator | validator annotations |