add ability to strip off leading/trailing spaces from email regularExpressionValidator?

  • Thread starter Thread starter Les Caudle
  • Start date Start date
L

Les Caudle

I'd been using
[\w\.-]+(\+[\w-]*)?@([\w-]+\.)+[\w-]+
as the validator for an email address.

If the user enters a leading or trailing space, the email is invalid.

1. How exactly does one trim leading/trailing spaces with a
RegularExpressionValidator?

2. Even though no complaints on email being invalid besides this - are there
better validation strings for emails?
 
Your post went unanswered. Have you resolved this issue? If you still need
help, please post the original question with your request.
 
I have not resolved this.

I need a validation expression for an email that will allow the user to enter a
space at the beginning or end (which I can easily strip off in code-behind).

It must also allow all valid emails. There are many of these email validation
strings floating around, but which to use? Which has actually been tested
against hundreds of thousands of valid emails and follows RFC-822?

Here is what I've been using. Some users will type in a space accidentally or
copy and paste their email and get a space - and they don't understand why it
doesn't work.

<asp:RegularExpressionValidator id="emailValid" ControlToValidate="email"
ValidationExpression="[\w\.-]+(\+[\w-]*)?@([\w-]+\.)+[\w-]+"

Thanks, Les Caudle
 
Back
Top