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

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?
 
A

Alvin Bruney [MVP]

Your post went unanswered. Have you resolved this issue? If you still need
help, please post the original question with your request.
 
L

Les Caudle

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top