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


Validates a string field using a regular expression.


  • 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.


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

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