husted 2004/01/16 19:32:11 Modified: doc/userGuide dev_validator.xml Log: Apply #26209 "Validator User Guide: New Section Listing Standard Validations" submitted by Niall Pemberton. Revision Changes Path 1.41 +179 -0 jakarta-struts/doc/userGuide/dev_validator.xml Index: dev_validator.xml =================================================================== RCS file: /home/cvs/jakarta-struts/doc/userGuide/dev_validator.xml,v retrieving revision 1.40 retrieving revision 1.41 diff -u -r1.40 -r1.41 --- dev_validator.xml 2 Jan 2004 11:55:38 -0000 1.40 +++ dev_validator.xml 17 Jan 2004 03:32:11 -0000 1.41 @@ -9,6 +9,7 @@ <author>David Winterfeldt</author> <author>James Turner</author> <author>Rob Leland</author> + <author>Niall Pemberton</author> <title>The Struts User's Guide - Validator Guide</title> </properties> @@ -153,6 +154,184 @@ ]]></code></pre> </section> + + <section href="builtin" name="Standard Built In Validations"> + + <p> + Validator is shipped with the following set of pre-defined validation rules. + </p> + <ul> + <li><strong>required</strong> - mandatory field validation. Has no variables. + <pre><code><![CDATA[ + <field property="name" depends="required"> + <arg0 key="customer.name"/> + </field> + ]]></code></pre> + </li> + <li><strong>requiredif</strong> - field dependant validator + <pre>Deprecated, use validwhen.</pre> + </li> + <li><strong>validwhen</strong> - validator for checking one field against another. + <pre>see later section titled <strong>Designing "Complex Validations with validwhen"</strong>.</pre> + </li> + <li><strong>minlength</strong> - validate input data isn't less than a specified minimum length. + Requires a <code>minlength</code> variable. + <pre><code><![CDATA[ + <field property="name" depends="required,minlength"> + <arg0 key="customer.name"/> + <arg1 name="minlength" key="${var:minlength}" resource="false"/> + <var><var-name>minlength</var-name><var-value>3</var-value></var> + </field> + ]]></code></pre> + </li> + <li><strong>maxlength</strong> - validate input data doesn't exceed a specified maximum length. + Requires a <code>maxlength</code> variable. + <pre><code><![CDATA[ + <field property="name" depends="required,maxlength"> + <arg0 key="customer.name"/> + <arg1 name="maxlength" key="${var:maxlength}" resource="false"/> + <var><var-name>maxlength</var-name><var-value>30</var-value></var> + </field> + ]]></code></pre> + </li> + <li><strong>mask</strong> - validate format according to a regular expression. + Requires a <code>mask</code> variable to specify the regular expression. + Since version 1.1, the regular expression must start + with a <code>^</code> and end with a <code>$</code> (see example below). + <pre><code><![CDATA[ + <field property="name" depends="required,mask"> + <msg name="mask" key="registrationForm.lastname.maskmsg"/> + <arg0 key="registration.name"/> + <var><var-name>mask</var-name><var-value>^[a-zA-Z]*$</var-value></var> + </field> + ]]></code></pre> + </li> + <li><strong>byte</strong> - validates that a field can be converted to a Byte. + <pre><code><![CDATA[ + <field property="age" depends="byte"> + <arg0 key="employee.age"/> + </field> + ]]></code></pre> + </li> + <li><strong>short</strong> - validates that a field can be converted to a Short. + <pre><code><![CDATA[ + <field property="productnumber" depends="short"> + <arg0 key="order.prodno"/> + </field> + ]]></code></pre> + </li> + <li><strong>integer</strong> - validates that a field can be converted to an Integer. + <pre><code><![CDATA[ + <field property="ordernumber" depends="integer"> + <arg0 key="order.number"/> + </field> + ]]></code></pre> + </li> + <li><strong>long</strong> - validates that a field can be converted to a Long. + <pre><code><![CDATA[ + <field property="ordernumber" depends="long"> + <arg0 key="order.number"/> + </field> + ]]></code></pre> + </li> + <li><strong>float</strong> - validates that a field can be converted to a Float. + <pre><code><![CDATA[ + <field property="amount" depends="float"> + <arg0 key="sale.amount"/> + </field> + ]]></code></pre> + </li> + <li><strong>double</strong> - validates that a field can be converted to a Double. + <pre><code><![CDATA[ + <field property="amount" depends="double"> + <arg0 key="sale.amount"/> + </field> + ]]></code></pre> + </li> + <li><strong>date</strong> - validates that a field can be converted to a Date. + This validation rule uses <code>java.text.SimpleDateFormat</code> to parse the date and + optionally either a <code>datePattern</code> or <code>datePatternStrict</code> variable can be used. + If no pattern is specified the default short date format is assumed. The difference + between using the <code>datePatternStrict</code> and <code>datePattern</code> variables + is that <code>datePatternStrict</code> checks additionally that the input data is the same + length as the pattern specified (so for example 1/1/2004 would fail with a pattern of <code>MM/dd/yyyy</code>). + <pre><code><![CDATA[ + <field property="saledate" depends="required,date"> + <arg0 key="myForm.saledate"/> + <var><var-name>datePattern</var-name><var-value>MM/dd/yyyy</var-value></var> + </field> + ]]></code></pre> + <pre><code><![CDATA[ + <field property="saledate" depends="required,date"> + <arg0 key="sale.orderdate"/> + <var><var-name>datePatternStrict</var-name><var-value>MM/dd/yyyy</var-value></var> + </field> + ]]></code></pre> + </li> + <li><strong>range</strong> - validate number range. + <pre>Deprecated, use intRange, floatRange or doubleRange.</pre> + </li> + <li><strong>intRange</strong> - validates that an integer field is within a specified range. + Requires <code>min</code> and <code>max</code> variables to specify the range. + This validator depends on the <code>integer</code> validator + which must also be in the field's <code>depends</code> attribute. + <pre><code><![CDATA[ + <field property="age" depends="required,integer,intRange"> + <arg0 key="employee.age"/> + <arg1 name="intRange" key="${var:min}" resource="false"/> + <arg2 name="intRange" key="${var:max}" resource="false"/> + <var><var-name>min</var-name><var-value>18</var-value></var> + <var><var-name>max</var-name><var-value>65</var-value></var> + </field> + ]]></code></pre> + </li> + <li><strong>floatRange</strong> - validates that a float field is within a specified range + Requires <code>min</code> and <code>max</code> variables to specify the range. + This validator depends on the <code>float</code> validator + which must also be in the field's <code>depends</code> attribute. + <pre><code><![CDATA[ + <field property="ordervalue" depends="required,float,floatRange"> + <arg0 key="order.value"/> + <arg1 name="floatRange" key="${var:min}" resource="false"/> + <arg2 name="floatRange" key="${var:max}" resource="false"/> + <var><var-name>min</var-name><var-value>100</var-value></var> + <var><var-name>max</var-name><var-value>4.99</var-value></var> + </field> + ]]></code></pre> + </li> + <li><strong>doubleRange</strong> - validates that a double field is within a specified range + Requires <code>min</code> and <code>max</code> variables to specify the range. + This validator depends on the <code>double</code> validator + which must also be in the field's <code>depends</code> attribute. + <pre><code><![CDATA[ + <field property="ordervalue" depends="required,double,doubleRange"> + <arg0 key="employee.age"/> + <arg1 name="doubleRange" key="${var:min}" resource="false"/> + <arg2 name="doubleRange" key="${var:max}" resource="false"/> + <var><var-name>min</var-name><var-value>100</var-value></var> + <var><var-name>max</var-name><var-value>4.99</var-value></var> + </field> + ]]></code></pre> + </li> + <li><strong>creditCard</strong> - validate credit card number format + <pre><code><![CDATA[ + <field property="name" depends="required, creditCard"> + <arg0 key="customer.cardnumber"/> + </field> + ]]></code></pre> + </li> + <li><strong>email</strong> - validate email address format + <pre><code><![CDATA[ + <field property="customeremail" depends="email"> + <arg0 key="customer.email"/> + </field> + ]]></code></pre> + </li> + + + </ul> + </section> + <section href="members" name="Constants/Variables">
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]