Apache Struts 2 Documentation > Home > Guides > Core Developers Guide > Validation > email validator |
EmailValidator checks that a given String field, if not empty, is a valid email address.
The regular expression used to validate that the string is an email address is:
\\b(^[_A-Za-z0-9-](\\.[_A-Za-z0-9-])*@([A-Za-z0-9-])+((\\.com)|(\\.net)|(\\.org)|(\\.info)|(\\.edu)|(\\.mil)|(\\.gov)|(\\.biz)|(\\.ws)|(\\.us)|(\\.tv)|(\\.cc)|(\\.aero)|(\\.arpa)|(\\.coop)|(\\.int)|(\\.jobs)|(\\.museum)|(\\.name)|(\\.pro)|(\\.travel)|(\\.nato)|(\\..{2,3})|(\\..{2,3}\\..{2,3}))$)\\b
<!-- Plain Validator Syntax --> <validators> <validator type="email"> <param name="fieldName">myEmail</param> <message>Must provide a valid email</message> </validator> </validators> <!-- Field Validator Syntax --> <field name="myEmail"> <field-validator type="email"> <message>Must provide a valid email</message> </field-validator> </field>