I'm trying to validate an email following the explanations on this page Email validation using jQuery, but I don't know why I get an error if I put this character ^ at the beginning of my expression:
function checkEmail(){
var email = this.innerHTML;
var emailPattern = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z]{2,4})+$/;
if (!emailPattern.test(email)){
alert("Invalid email address.");
}
else {
alert("Valid email address.");
}
}
If I use the other one (without ^ and +$) it works perfectly:
var emailPattern = /[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/;
Just to understand it, What is wrong with my first expression?
Here is a fiddle that demonstrate my problem: http://jsfiddle.net/5en4cxy9/
Thanks,