The asp.net RegularExpressionValidator email regex does not validate all valid e-mailaddresses

In a project I’ve been working on I discovered that the Visual Studo built in regex for email that you get when you work with the RegularExpressionValidator doesn’t work for some email addresses that actually are valid. This goes for email addresses that has for example a hyphen (-) or a dot (.) directly in front of the @, i.e. emailme-@hotmail.com.

The built in regular expression looks like this:

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

There are a lot of resources on RegEx on the web so I wont walk it through, let’s just take a look at the problem described above and modify it instead of googling up a working one.

The second instance of \w+ means word boundary, 1 or more times. Change this + to a * to say 0 or more times instead. So now the complete regular expression looks like this:

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

Now all I want is a way to save this change in Visual Studio.

1 comment :

  1. Iv made the changes as you said....and it works just fine..........Keep it up......

    ReplyDelete