Apache Struts 2 Documentation > Home > Guides > Core Developers Guide > Validation > regex validator
#editReport()

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.
  • trim - Boolean (Optional). Sets whether the expression should be trimed before matching. 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>