regex validator Menu Toggle navigation Home Welcome Download Releases Announcements License Thanks! Sponsorship Privacy Policy Support User Mailing List Issue Tracker Reporting Security Issues Commercial Support End-of-Life Versions Version Notes Security Bulletins IntelliJ IDEA plugin Maven Project Info Struts Core Dependencies Plugin Dependencies Documentation Birds Eye Key Technologies Kickstart FAQ Wiki Getting Started Security Guide Core Developers Guide Tag Developers Guide Maven Archetypes Plugins Struts Core API Tag reference FAQs Plugin registry Contributing You at Struts How to Help FAQ Development Lists Submitting patches Source Code and Builds Coding standards Contributors Guide Release Guidelines PMC Charter Volunteers Source Repository Updating the website Edit on GitHub regex validator Description Parameters Examples 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. regexp - The RegExp expression 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 trimmed before matching. Default is true. regexExpression - String (Optional). Defines regExp expression as an OGNL expression - will be evaluated to String. caseSensitiveExpression - String (Optional). Defines caseSensitive param as an OGNL expression - will be evaluated to Boolean. trimExpression - String (Optional). Defines trim param as an OGNL expression - will be evaluated to Boolean. You can mix normal params with expression aware params but thus was not tested. Warning: do not use ${regexExpression}, ${caseSensitiveExpression} and ${trimExpression} as an expression as this will turn into infinitive loop! Examples <validators> <!-- Plain Validator Syntax --> <validator type="regex"> <param name="fieldName">myStrangePostcode</param> <param name="regex"><![CDATA[([aAbBcCdD][123][eEfFgG][456])]]></param> </validator> <!-- Field Validator Syntax --> <field name="myStrangePostcode"> <field-validator type="regex"> <param name="regex"><![CDATA[([aAbBcCdD][123][eEfFgG][456])]]></param> </field-validator> </field> <!-- Field Validator Syntax with expressions --> <field name="myStrangePostcode"> <field-validator type="regex"> <param name="regexExpression">${regexValue}</param> <!-- will be evaluated as: String getRegexValue() --> <param name="caseSensitiveExpression">${caseSensitiveValue}</param> <!-- will be evaluated as: boolean getCaseSensitiveValue() --> <param name="trimExpression">${trimValue}</param> <!-- will be evaluated as: boolean getTrimValue() --> </field-validator> </field> </validators> Copyright © 2000-2025 The Apache Software Foundation. Apache Struts, Struts, Apache, the Apache feather logo, and the Apache Struts project logos are trademarks of The Apache Software Foundation. All Rights Reserved. Logo and website design donated by SoftwareMill. Follow @x