Check if an email was typed in text field with jQuery

Asked

Viewed 278 times

1

Good afternoon!

How do I check if an email has been typed within a text field?

I need to identify when the user clicks outside the field, whether an email was typed or just a name, for example.

Thank you!

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: http://rogeralmeida.com.br/blog/2011/06/12/validacao-de-email-utilizando-expressoes-regulares-e-jquery/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.