Validatro framework to become part of Jakarta's public projects, you can download a separate validator framework from http://jakarta.apache.org/commons/, which has been stuck in struts.
Validator mainly relies on two jar packs
Jakarta-oro.jar:-provides a set of classes that handle text, with text substitution, filtering, and segmentation.
Commons-validator.jar: Provides a simple, extensible validation framework that includes common validation methods and validation rules.
Using this frame in struts, you need to add these two packages and it feels good to use them.
Here is a brief introduction.
Validator uses a two-XML file to configure validation rules, respectively, Validation.xml,validator-rules.xml. In struts applications, it needs to be placed in the Web-inf directory.
1. Validator-rules.xml
This file contains a set of validation rules that apply to all struts applications. Generally, you do not need to modify this file unless you want to modify or extend the default rule. If you want to put it in another XML file instead of adding it directly to the Validator-rules.xml file, you do not have to modify the Validator-rules.xml file when the validator is upgraded.
2. Validator.xml file
This file is for specific struts applications, and he can configure validation rules for Actionform in the application. Instead of coding to implement validation.
For example, a validation landing form example, requires that the user name must be filled in, secret requirements must be filled, maximum, minimum length and its content requirements.
Code
<form-validation>
<global>
<!--A string consisting of numbers, 26 English letters, or underscores;
<const Ant>
<constant-name>pwd</constant-name>
<onstant-value>^\w+$</onstant-value& Gt
</constant>
</global>
<formset>
<form name= "LoginForm"
<!--the user name here uses the mailbox, the authentication uses the regular expression to authenticate the property=, the
<field user.userid depends= "required"
<arg0 key= "User.userid"/>
</field>
<field property= "User.userpwd" depends= , Minlength,maxlength,mask "
<!--msg name=" Mask "key=" Errors.invalid "/-->
<arg0 key = "User.userpwd"/>
<arg1 name= "minlength" key= "${var:minlength}" resource= "false"/>
&L T;arg2 name= "maxlength" key= "${var:maxlength}" resource= "false"/>
<var>
<var-name >mask</var-name
<var-value>^\w+$</var-value>
</var>
<var>
<var-name>minlength</var-name>
<var-value>6</var-value>
</var& Gt
<var>
<var-name>maxlength</var-name>
<var-value>20< /var-value>
</var>
</field>
</form>
</formset>
< /form-validation>
The syntax for validator.xml and validator-rules.xml files is not explained here.