I have a RegularExpressionValidator on my page which validates an email using this
<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>
This works for things like “hello@hello.com”
but if the user cut and pastes emails in, sometimes you get things like “hello@hello.com ” or ” hello@hello.com “.
Is it possible to specify in the regular expression that I would like to trim the white spaces before validating the email?
You could just add white-space checks to your regex: