Megamind Saiko
Megamind Saiko

Reputation: 697

Javascript escaping the dot in regex

I'm trying to validate email addresses in javascript, I tried this

/[A-Za-z0-9_\-]+\@[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-]+/

but it matched the input "b@aaa", where the middle "a" letter should be a dot to match. and tried not to escape the dot like this:

/[A-Za-z0-9_\-]+\@[A-Za-z0-9_\-]+.[A-Za-z0-9_\-]+/

and it matched the input too.

Upvotes: 0

Views: 1587

Answers (1)

David Xu
David Xu

Reputation: 5597

I think you need 2 backslashes:

/[A-Za-z0-9_\-]+\@[A-Za-z0-9_\-]+\\.[A-Za-z0-9_\-]+/

Upvotes: 1

Related Questions