3

I have a regex which validate emails.

([a-z0-9_\.-]+\@[\da-z\.-]+\.[a-z\.]{2,6})

some emails start with "." "_" "-" and it catches it as a valid. How can I write a regex to start with characters or digits? I have text so anchor ^ doesn't working.

Regards

wtflolwut
  • 81
  • 1
  • 8

2 Answers2

9

EDIT This question/answer should have been marked as the duplicate: Using a regular expression to validate an email address


Earlier this year I had the same need as you. Found out someone created a dedicated site for it: http://emailregex.com/

The regex posted there are according to RFC5322 and to my knowledge, works really well.

Also, to validate REGEX, I love this site.

Joel Bourbonnais
  • 2,618
  • 3
  • 27
  • 44
1

_test@example.com and -test@example.com are both valid per RFC 822, you'd be better using a proper (non-regex) e-mail validator or perhaps by looking at this response.