Custom Validators in STRUTS

Struts Validator framework provides many validation rules that can be used in the web applications. If you application needs special kind of validation, then you can extend the validator framework to develop your own validation rule.

The client-side validation in Struts is well known. Here are some of the available features:

* required
* requiredif
* validwhen
* minlength
* maxlength
* mask
* byte
* short
* integer
* long
* float
* double
* byteLocale
* shortLocale
* integerLocale
* longLocale
* floatLocale
* doubleLocale
* date
* intRange
* longRange
* floatRange
* doubleRange
* creditCard
* email
* url

These are found in the validator-rules.xml inside the tags. The validator-rules.xml file is found in the commons-validator jar.

Let us know create a new validator for entering the name field of a form. The form should accept only "administrator" for the name field. To accomplish this edit the validator-rules.xml and add the following code under the tag:


0) {
jcv_handleErrors(fields, focusField);
}
return isValid;
}
]]>