Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex Email - Ignore leading and trailing spaces?

Tags:

.net

regex

email

We are using the following to do an email validation in ASP.NET:

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

How can this be modified to ignore leading and trailing spaces?

The actual trimming we handle in code on postback but the validator is triggering as being invalid if the user has an extra space often due to copying and paste.

like image 394
schooner Avatar asked Feb 21 '09 18:02

schooner


1 Answers

You can place \s* before and after your pattern and it should work properly.

like image 146
localshred Avatar answered Oct 06 '22 00:10

localshred