0

I know many of you have already read a lot of questions about regex and email, but I can't solve my problem!

I'm using Javascript and I have to check my email, everything is ok with my regular expression except one thing: it doesn't check correctly '_' char after '@'. The strange thing is that regex compilers online check it correctly, but when I use it on my webapp it goes wrong.

This is my regular expression:

[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?

And here I'll write some examples:

teo@teo.teo correct match

teo@_teo.teo match fails correctly

teo@teo_teo.teo the compiler match return true, but it should fail

The problem, as I wrote before, is that some online compiler checks everything correctly.

Thank you for your help.

Matteo

Community
  • 1
  • 1
  • HTML5 uses `^[a-zA-Z0-9.!#$%&'*+/=?^_\`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$` - why do you need to do your own? – Antti Haapala -- Слава Україні Feb 20 '15 at 08:53
  • are you sure that you are matching the entire email address (do you have ^ and $ placeholders at the start and end of the regex you are using)? the regex might be matching because it has found a substring within the email address that matches rather than the whole thing – codebox Feb 20 '15 at 08:54
  • It is rather pointless to "fix" *yet another* email matching regex, since there are so much written about this question, as you yourself pointed out. – Antti Haapala -- Слава Україні Feb 20 '15 at 08:55

0 Answers0