Reputation: 139
I am trying to do validation for email through javascript for that I have used one regex pattern i.e -
var filter = /[a-z0-9]+\@[a-z0-9]+\.[a-z]+/;
alert("match is=="+filter.test(email));
I expected that the regex [a-z] will only match alphabets from a-z in lowercase but when i did testing what i expected was wrong..
when i entered Abc or aBC or @&c or &&&b***
it returns to true...i mean any special character combined with lowercase alphabet a-z or also uppercase alphabet combined with lowercase returns to true..Why is it so?
Please guide someone
Upvotes: 0
Views: 659
Reputation: 4293
You should use:
var filter = /^[a-z0-9]+\@[a-z0-9]+\.[a-z]+$/;
alert("match is=="+filter.test(email));
Upvotes: 2