0

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

Sergey Scopin
  • 2,217
  • 9
  • 39
  • 67

3 Answers3

3

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/

RahulB
  • 2,070
  • 1
  • 18
  • 26
1
$(document).on("click","#sendPhysButton", function(event){
    var reg =  /.*@.*\..*/;
    alert(reg.test($("#lastNameSend").val()));
    event.preventDefault();
});

Hope can help you

yuanzm
  • 114
  • 6
0

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.

3rik82
  • 45
  • 7