Nishant Kumar
Nishant Kumar

Reputation: 6083

Regular expression for email in asp.net

There are a lot of question on stack overflow possibly for regular expression for email. I assume I will not get taged as duplicate question...:)

Currently I am using regular expression for email address:

\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

This works fine with following: [email protected]

What I want to allowed here user can give space at begining or at ending and possibly both for instance: " [email protected] " I want to pass it by regular expression Currently it's giving Invalid I believe it should be.

What I tried ^[ \t]+|[ \t]+$ + \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*

But It's not working I am not more familiar with how to write regular expression. Currently I m trying to learn from Here http://www.regular-expressions.info/examples.html.

Upvotes: 0

Views: 750

Answers (1)

OJ Raqueño
OJ Raqueño

Reputation: 4561

Try \s*\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*\s*.

Upvotes: 3

Related Questions