0

i'm working on my site, but i have a problem with the email checker, i dont get why it wont work (I HAVE NEVER USED JS BEFORE) so i did like that:

var flag=true;

    var st = Form1["email"].value.indexOf("@");

    if (st == -1)

    {

        alert("You must insert @ in email address.");

        flag=false;

    }

Can some one help me? thanks for the help

Gal Israel
  • 83
  • 1
  • 2
  • 7
  • 3
    Check this thread, http://stackoverflow.com/questions/940577/javascript-regular-expression-email-validation Solved using regular expressions. – user1390282 Jun 13 '13 at 14:27
  • 4
    You need to learn Javascript. – SLaks Jun 13 '13 at 14:28
  • 3
    @zenith how do you learn without trying things and encountering stuff that you don't understand? Books and articles only go so far. (Now why do they ask write my code questions...) – Ben McCormick Jun 13 '13 at 14:30
  • 1
    @ben336 "Books and articles only go so far" - I wouldn't say that, good books have endless possibilities. I'd rather spend a few hours reading beforehand and save myself time in the long run. – dsgriffin Jun 13 '13 at 14:39

2 Answers2

0

Regular expressions are your friend, try this:

function validateEmail(email) { 
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]  {1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}
Karl Anderson
  • 34,606
  • 12
  • 65
  • 80
0
    var regex = /^[0-9a-zA-Z]+([0-9a-zA-Z]*[-._+])*[0-9a-zA-Z]+@[0-9a-zA-Z]+([-.][0-9a-zA-Z]+)*([0-9a-zA-Z]*[.])[a-zA-Z]{2,6}$/;

   if (regex.test(Form1["email"].value) == false) 
   {
   alert("Invalid E-mail address!");
   }
Jake Mogra
  • 51
  • 9