17.7. Types of validation available

The following shows a listing of the various types of validations possible. Of course, the developer is free to add custom validation-rules as needed.

17.7.1. required

Value is required, and must be input by the end-user.

        ApplicationResource.properties:
            
                errors.required={0} is required.
                myForm.title.displayname=Title
 

            
        Validation.xml: 
 
    <field property="title" depends="required"> 
                    <msg name="required" key="errors.required" resource="true"/> 
                    <arg0 name="required" key="myForm.title.displayname" resource="true"/> 
    </field> 
    
                
            
        Result when error: 
                Title is required.
 
      

17.7.2. mask

Validation made via a "regular expression".

        ApplicationResource.properties:
                myForm.error.title.mask=The Title must begin with an uppercase character
                 and contain alphanumeric characters only.
            
            
            
        Validation.xml: 
    <field property="title" depends="mask"> 
                    <msg name="mask" key="myForm.error.title.mask" resource="true"/> 
                    <var> 
                        <var-name>mask</var-name> 
                        <var-value>^[A-Z][A-Za-z0-9\s]*$</var-value> 
                    </var> 
    </field> 
            
                
            
        Result when error: 
                The Title must begin with an uppercase character
                 and contain alphanumeric characters only.
 
      

17.7.3. range

Validation made via a "regular expression".

        ApplicationResource.properties:
                errors.range={0} must be between {1} and {2}.
                myForm.age.displayname=age
 

            
        Validation.xml: 
    <field    property="age" depends="range">
                 
                    <msg name="range" key="errors.range"/> 
                    <arg0 name="range" key="myForm.age.displayname" resource="true"/> 
                    <arg1 name="range" key="${var:min}" resource="false"/> 
                    <arg2 name="range" key="${var:max}" resource="false"/> 
                    
                    <var> 
                        <var-name>min</var-name> 
                        <var-value>1</var-value> 
                    </var>
                     
                    <var> 
                        <var-name>max</var-name> 
                        <var-value>110</var-value> 
                    </var>
                     
    </field>
                
                 
            
        Result when error: 
                age must be between 1 and 110.
 
      

17.7.4. byte, short, long, integer, double, float

Validation to insure a specific data type. Each of these validations may be used separately.

        ApplicationResource.properties:
                errors.integer={0} should be of type integer.
                myForm.age.displayname=age
 

            
        Validation.xml: 
                <field property="age" depends="integer"> 
                    <msg name="integer" key="errors.integer"/> 
                    <arg0 name="integer" key="myForm.age.displayname" resource="true"/> 
                </field>
                    
                     
            
        Result when error: 
                age should be of type integer.
     
      

17.7.5. minlength

Validates if the number of characters input by the user, respects the minimum number required.

        ApplicationResource.properties:
                errors.minlength={0} cannot contain less than {1} characters.
                myForm.description.displayname=Description


            
        Validation.xml: 
                <field property="description" depends="minlength"> 
                    <msg name="minlength" key="errors.minlength"/> 
                    <arg0 name="minlength" key="myForm.description.displayname" resource="true"/> 
                    
                    <var> 
                        <var-name>minlength</var-name> 
                        <var-value>25</var-value> 
                    </var> 
    </field>
                
                 
            
        Result when error: 
                Description cannot contain less than 25 characters.
     
      

17.7.6. maxlength

Validates if the number of characters input by the user, respects the maximum number required.

        ApplicationResource.properties:
                errors.maxlength={0} cannot contain more than {1} characters.
    myForm.description.displayname=Description
 

            
        Validation.xml: 
                <field property="description" depends="maxlength"> 
                    <msg name="maxlength" key="errors.maxlength"/> 
                    <arg0 name="maxlength" key="myForm.description.displayname" resource="true"/> 
                    
                    <var> 
                        <var-name>maxlength</var-name> 
                        <var-value>25</var-value> 
                    </var> 
    </field>
                
                 
            
        Result when error: 
                Description cannot contain more than 25 characters.
 
      

17.7.7. date

Validates if the date input is a valid date. This validation requires two arguments: 'SimpleDateFormat' and a (date) pattern. Valid patterns include:

  • datePattern

  • datePatternStrict which validates length.

Hence, if the SimpleDateFormat is set to 'yyyy-MM-dd' and the user input '2002-4-4', using 'datePatternStrict' would return an error. (Expecting 10 characters got 8)

        ApplicationResource.properties:
                errors.date={0} is not a valid date.
                myForm.opendate.displayname=Start Date
 

    
        Validation.xml: 
                    <field property="opendate" depends="date"> 
                        <msg name="date" key="errors.date"/> 
                        <arg0 name="date" key="myForm.opendate.displayname" resource="true"/> 
                        
                        <var> 
                            <var-name>datePatternStrict</var-name> 
                            <var-value>yyyy-MM-dd</var-value> 
                        </var> 
                    </field>
                    
                     
    
        Result when error: 
                    Start Date is not a valid date.
 
    
      

17.7.8. email

Validates an e-mail address.

        ApplicationResource.properties:
                errors.email={0} does not contain a valid e-mail address.
                myForm.email.displayname=User E-mail address
 

            
        Validation.xml: 
    <field property="email_user" depends="email"> 
                    <msg name="email" key="errors.email"/> 
                    <arg0 name="email" key="myForm.email.displayname" resource="true"/> 
    </field>
                
                 
            
        Result when error: 
                User E-mail address does not contain a valid e-mail address.
 
    
      

17.7.9. creditcard

Validates a credit card number (using checksum).

        ApplicationResource.properties:
                errors.creditcard={0} does not contain a valid credit card number.
                myForm.creditcard.displayname=Client credit card
 

            
        Validation.xml: 
    <field property="email_user" depends="creditcard"> 
                    <msg name="creditcard" key="errors.creditcard"/> 
                    <arg0 name="creditcard" key="myForm.creditcard.displayname" resource="true"/> 
    </field> 
    
                
            
        Result when error: 
                Client credit card does not contain a valid credit card number.
 
    
      

Please refer to the sample application 'bugtracker' for a detailed exemple of using validation within dbForms. This application can be found in the distribution package.