如何在验证前进行正则表达式修剪?

Dis*_*ive 6 .net regex validation

我的页面上有一个RegularExpressionValidator,用于验证使用此邮件的电子邮件

    <asp:RegularExpressionValidator ID="valEmailExpression" 
    runat="server" 
ErrorMessage="Your email address does not appear to be of a valid form. (eg: your.name@yourorganisation.com)"
    ControlToValidate="txtUsername" EnableClientScript="false" 
    ValidationExpression=**"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"**
    Display="None"></asp:RegularExpressionValidator>
Run Code Online (Sandbox Code Playgroud)

这适用于"hello@hello.com"之类的东西

但如果用户剪切并粘贴电子邮件,有时会收到"hello@hello.com"或"hello@hello.com"之类的内容.

是否可以在正则表达式中指定我想在验证电子邮件之前修剪空格?

And*_*per 5

您可以在正则表达式中添加空格检查:

\s*\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*\s*
Run Code Online (Sandbox Code Playgroud)