Working with Dates in Validator Framework

Working with Dates in Validator Framework

Previous Home Next

 

The Date rule checks to see if the field is valid date.This validation rule uses java.text.SimpleDateFormat to parse the date and either a datePattern or datePatternStrict variable can be used .it is optional. If no pattern is specified the default short form of the date format is used.

 
The only difference between using the datePatternStrict and datePattern variables is that datePatternStrict checks additionally that the input data is the same length as the pattern specified.

Example:- The datePatternStrict variable will ensure that 1/1/2012 would fail with a pattern of MM/dd/yyyy because only 01/01/2012 works.

Create validation.xml file :- 

<form name="inputForm">
<field property="name" depends="required,email">
<arg key="inputForm.name"/></field>
<field property="birthdob" depends="required,date">
<arg key="inputForm.birthdob"/>
<var>
<var-name>datePattern</var-name>
<var-value>MM-dd-yy</var-value>
</var>
</field>
</form>

Previous Home Next