Apache Struts 2 Documentation > Home > Guides > Core Developers Guide > Validation > regex validator
Added by tm_jee, last edited by Philip Luppens on Feb 10, 2007  (view change) show comment

Description

Validates a string field using a regular expression.

Parameters

  • fieldName - The field name this validator is validating. Required if using Plain-Validator Syntax otherwise not required
  • expression - The RegExp expression REQUIRED
  • caseSensitive - Boolean (Optional). Sets whether the expression should be matched against in a case-sensitive way. Default is true.

Examples

<validators>
    <!-- Plain Validator Syntax -->
    <validator type="regex">
        <param name="fieldName">myStrangePostcode</param>
        <param name="expression"><![CDATA[([aAbBcCdD][123][eEfFgG][456])]]<>/param>
    </validator>

    <!-- Field Validator Syntax -->
    <field name="myStrangePostcode">
        <field-validator type="regex">
           <param name="expression"><![CDATA[([aAbBcCdD][123][eEfFgG][456])]]></param>
        </field-validator>
    </field>
</validators>