Javascript Validation Configured with Localized Variables.
The purpose of this page is to demonstrate Validator configured to use variables from message resources. So, for example, the date validator can get the format appropriate for the user's Locale - enabling localized validation using just one form in the validation config file.
Employee Information
The above fields use the following validation rules in a localized way...
- Name -
minlength and maxlength..
- Zip Code -
minlength, maxlength and validwhen..
- Phone Number -
mask.
- Date of Birth -
date(not strict) .
- Age -
intRange..
- Date of Employment -
date(strict).
- Employee Number -
longRange..
- Annual Salary -
doubleRange..
- Weekly Hours -
floatRange..
Notes Below...
- The validation config is in validation.xml in the /webapps/struts-examples/WEB-INF/validator directory.
- Two message resources bundles have been used - one for normal text and the other for validation variables:
- General text (bundle key i18nExample) is in I18nExample.properties
- Validation variables (bundle key i18nVariables) are in I18nExampleVariables.properties
- N.B.Its important to configure the resource bundle containing validation variables to return null if not found. See the struts-config.xml for an example of this.