Validate email in JavaScript [duplicate]

6

Good afternoon,

I have a question in an exercise that I have to solve and I wanted to ask you to help me:

How do I make a function in JavaScript that takes a string as an argument and verifies that an email is valid, that is, if it contains @ is an email. And the function returns a boolean. Thank you

    
asked by anonymous 03.07.2015 / 13:48

1 answer

4

You can validate using this function:

function IsEmail(email){
    var exclude=/[^@-.w]|^[[email protected]]|[._-]{2}|[@.]{2}|(@)[^@]*1/;
    var check=/@[w-]+./;
    var checkend=/.[a-zA-Z]{2,3}$/;
    if(((email.search(exclude) != -1)||(email.search(check)) == -1)||(email.search(checkend) == -1)){return false;}
    else {return true;}
}

source: link

    
03.07.2015 / 13:56