java 从Struts 2.1升级到Struts 2.3时面临的电子邮件验证问题

qc6wkl3g  于 2023-05-12  发布在  Java
关注(0)|答案(2)|浏览(190)

在我的应用程序中,我使用了Struts XML验证,它在Struts 2.1中工作得很好,我刚刚将其升级到2.3,现在电子邮件验证不适用于jamshed.katta@icab.cat
我的正则表达式是这样的

<field name="email">
    <field-validator type="requiredstring">
        <message key="register.validation.email" />
    </field-validator>
    <field-validator type="email">
    <param name="regexExpression">\\b^['_a-z0-9-\\+]+(\\.['_a-z0-9-\\+]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)\*\.([a-z]{2}|aero|arpa|asia|biz|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|nato|net|org|pro|tel|travel|xxx|**cat**)$\\b</param>
        <message key="register.validation.email.format" />
    </field-validator>
</field>
xurqigkl

xurqigkl1#

试试这个正则表达式验证器:

<field name="email">
    <field-validator type="requiredstring">
        <message key="register.validation.email" />
    </field-validator>
    <field-validator type="regex">
      <param name="regexExpression"><![CDATA[^['_a-z0-9-\+]+(\.['_a-z0-9-\+]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2}|aero|arpa|asia|biz|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|nato|net|org|pro|tel|travel|xxx|cat)$]]></param>
        <message key="register.validation.email.format" />
      <param name="caseSensitiveExpression">${false}</param>
      <param name="trimExpression">${true}</param>
    </field-validator>
</field>

它还应用了caseSensitiveExpression参数和trimExpression参数。有关regex validator的更多信息,您可以在文档中找到。

jq6vz3qz

jq6vz3qz2#

如果你想要一个像下图这样的正则表达式:

你可以像这样修改你的regexp:

(^['_a-z0-9-\\+]+(?:\.['_a-z0-9-\\+]+)*@[a-z0-9-]+(?:\.[a-z0-9-]+\.?)*(?:[a-z]{2}|aero|arpa|asia|biz|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|nato|net|org|pro|tel|travel|xxx|cat)$)

DEMO and Explanation

相关问题