Struts1.3 ValidatorForm、DynValidatorForm使用

1. 使用ValidatorForm

一、准备:

1)common-validator.jar包
2)在struts-config.xml添加插件

<plug-in className="org.apache.struts.validator.ValidatorPlugIn"> <set-property property="pathnames" value="/org/apache/struts/validator/validator-rules.xml, /WEB-INF/validation.xml"/> </plug-in>


3)validation.xml(1.2的话还要validation-rule.xml)

 

<form-validation> <global> <constant> <constant-name>phone</constant-name> <constant-value> ^/(?(/d{3})/)?[-| ]?(/d{3})[-| ]?(/d{4})$ </constant-value> </constant> <constant> <constant-name>zip</constant-name> <constant-value>^/d{5}/d*$</constant-value> </constant> </global> <formset> <constant> <constant-name>zip</constant-name> <constant-value>^/d{5}(-/d{4})?$</constant-value> </constant> <form name="submitForm"> <field property="customer.firstName" depends="required,mask,minlength"> <arg0 key="submitForm.customer.firstname" /> <arg1 name="minlength" key="${var:minlength}" resource="false" /> <var> <var-name>mask</var-name> <var-value>^/w+$</var-value> </var> <var> <var-name>minlength</var-name> <var-value>5</var-value> </var> </field> <field property="customer.lastName" depends="required,mask,maxlength"> <msg name="mask" key="submitForm.lastname.maskmsg" /> <arg0 key="submitForm.customer.lastname" /> <arg1 name="maxlength" key="${var:maxlength}" resource="false" /> <var> <var-name>mask</var-name> <var-value>^[a-zA-Z]*$</var-value> </var> <var> <var-name>maxlength</var-name> <var-value>10</var-value> </var> </field> <field property="customer.address" depends="required"> <arg0 key="submitForm.customer.address" /> </field> <field property="customer.city" depends="required,mask"> <arg0 key="submitForm.customer.city" /> <var> <var-name>mask</var-name> <var-value>^[a-zA-Z]*$</var-value> </var> </field> <field property="customer.state" depends="required,mask"> <arg0 key="submitForm.customer.state" /> <var> <var-name>mask</var-name> <var-value>^[a-zA-Z]*$</var-value> </var> </field> <field property="customer.zip" depends="required,mask"> <arg0 key="submitForm.customer.zip" /> <var> <var-name>mask</var-name> <var-value>${zip}</var-value> </var> </field> <field property="customer.phone" depends="mask"> <arg0 key="submitForm.customer.phone" /> <var> <var-name>mask</var-name> <var-value>${phone}</var-value> </var> </field> <field property="customer.email" depends="required,email"> <arg0 key="submitForm.customer.email" /> </field> <field property="creditcard.date" depends="required,date"> <arg0 key="submitForm.creditcard.date" /> <var> <var-name>datePatternStrict</var-name> <var-value>MM-dd-yyyy</var-value> </var> </field> <field property="creditcard.number" depends="required,creditCard"> <arg0 key="submitForm.creditcard.number" /> </field> </form> </formset> </form-validation>

 

 

你可能感兴趣的:(struts)