Check if an email was typed in jQuery text field [duplicate]

1

Good afternoon!

How do I check if an email was typed inside a text field?

I need to identify when the user clicks off the field, if an email has been typed or just a name, for example.

Thank you!

    
asked by anonymous 19.04.2017 / 22:07

1 answer

1

Here the guy put in the form submit, but it can be in the field onblur.

In this case you use Regex and the JQuery selector:

$(document).ready(function(){
   $("#form1").submit(function(){
       var email = $("#email").val();
       if(email != "") {
           var filtro = /^([w-]+(?:.[w-]+)*)@((?:[w-]+.)*w[w-]{0,66}).([a-z]{2,6}(?:.[a-z]{2})?)$/i;
           if(filtro.test(email)) {
               alert("Este endereço de email é válido!");
               return true;
           } else {
               alert("Este endereço de email não é válido!");
               return false;
           }
       } else {
           alert('Digite um email!'); return false;
       }
   });

});

Source: link

    
19.04.2017 / 22:15