Ok now I try to check if input email is valid with this regexp:
$("#lastNameSend").val().search(/.*@.*\..*/)
This never returns anything. Why? here is fiddle
Ok now I try to check if input email is valid with this regexp:
$("#lastNameSend").val().search(/.*@.*\..*/)
This never returns anything. Why? here is fiddle
First your fiddle function is not having opening curly brackets--
$(document).on("click","#sendPhysButton", function(event)
alert($("#lastNameSend").val().search(/.*@.*\..*/));
event.preventDefault();
});
It should be
$(document).on("click","#sendPhysButton", function(event)
{
alert($("#lastNameSend").val().search(/.*@.*\..*/));
event.preventDefault();
});
Now it will return -1 if regex is not satisfied.Also, I prefer to use this regex-
/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/
Fiddle - http://jsfiddle.net/jupnzty0/15/
$(document).on("click","#sendPhysButton", function(event){
var reg = /.*@.*\..*/;
alert(reg.test($("#lastNameSend").val()));
event.preventDefault();
});
Hope can help you
This is a pretty waterproof email check:
/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&''*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i
If it throws -1, you can implement an error message.