I need to do some validation on my system registration screen and decided to use RegEx to validate the email address.
I found a handy little website that allows you to edit and test RegEx to see if you get the correct resulst. mine should bascially allow for something like
This is what I came up with
It all works fine, apart for some reason it doesn't like it if you put a - in your email! From what I can see it should allow
but it doesn't!
Confussed!
Any suggestions?
KS [ June 26, 2008: Message edited by: Keith Seller ]
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
Try putting the hyphen first, like [-a-zA-Z0-9\\_\\.]
But: If you try to make the regexp overly specific it can happen all too easily that it disallows some proper addresses. I generally use "^\\S+@([-\\w]+\\.){1,4}[a-z]{2,6}$" with a few additional checks (like a valid TLD).
One problems I see with the one you posted is that various valid TLDs that have more than 3 characters (like .travel, .museum and .name) would fail to be recognized. [ June 26, 2008: Message edited by: Ulf Dittmer ]