Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

@{ID} eg. @FirstnameValidator

Annotations that start with @ followed by an ID, 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:

 

Info
  1. object Person
  2. {
  3.     @FirstnameValidator("validr.msg.fname")
  4.     string fname;
  5.  
  6.     @SurnameValidator("validr.msg.sname")
  7.     string sname;
  8. }

 

 

validator

Used to declare a field validator

 

Info
  1. validator FirstnameValidator 
  2. {
  3.     minlen(2); maxlen(250);
  4. }
  5. validator AgeValidator 
  6. {
  7.     minval(0);
  8. }

 

 

Atomic validators

Table of Contents

 

Available Atomic Validators

These are the building blocks used for creating complex validators:

 

validator/usagedescription
notnull();Check that the attribute is not null. This validator does not take any arguments.

 

regex
regex("^[A-Z a-z]*$");

Checks that the value conforms to a regular expression.

 

Info//

Allows upper & lower case and spaces.

regex("^[A-Za-
Z a
z0-
z
9 ]*$");
//
Another regex example. Alphanumeric with spaces.
regex("
^[A-Za-z0
^27[0-9]*$");
//
Another regex example. Number starting with 27
  • regex("^27[0-9]*$");
  • // Email
    .
    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.

     

    Infominval(3.145
    maxval(6.18);

     

    maxval

    Checks that the values is not greater than the supplied maximum value.

     

    Infomaxval(6.18
    minlen(2);

     

    minlen

    Checks that a string value does not have less characters than the supplied minimum value.

     

    Infominlen(2
    maxlen(255);

     

    maxlen

    Checks that a string value does not have more characters than the supplied maximum value.

     

    Info
    1. maxlen(255);

     

    Some examples:

     

    Info
  • validator PersonNameValidator {
  •     notnull(); minlen(2); maxlen(50);
  • }
  •  
  • validator AgeValidator {
  •     notnull(); minval(0);
  • }
  •  
  • validator CTMetroPhoneNumber {
  •     notnull(); regex(“

     

     

    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
    languagejava
    titleValidator Examples
    linenumberstrue
    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
    linenumberstrue
    object Person
    {
        @FirstnameValidator("validr.msg.fname")
        string fname;
     
        @SurnameValidator("validr.msg.sname")
        string sname;
    }

     

    Additional Mentions and References

     

    Excerpt
    hiddentrue

     notnull() etc. | validator | validator annotations