Praetorian Posted November 14, 2007 Share Posted November 14, 2007 I'm writing a script to validate an email address, and it's giving me a headache.I can't for the life of me figure out why this block isn't working... var the_dot = document.frm.user_email.value.indexOf(".");if (the_dot == frm.user_email.length -1){ alert("Your Email Address is Invalid."); frm.user_email.focus(); return (false); } Link to comment Share on other sites More sharing options...
Synook Posted November 14, 2007 Share Posted November 14, 2007 Umm... if indexOf() cannot find a character then it will return -1, so if you are checking for a period's existance your function will be var the_dot = document.frm.user_email.value.indexOf(".");if (the_dot == -1){ alert("Your Email Address is Invalid."); frm.user_email.focus(); return (false); } Link to comment Share on other sites More sharing options...
Praetorian Posted November 14, 2007 Author Share Posted November 14, 2007 I actually already have a block performing that function. What the problem block is supposed to be doing is making sure that there are characters after the period. Which is why I'm confused. Because if the index of the dot is -1 of the email's length, then isn't it the last character in the line? Making the email invalid? Yet that block I wrote always without giving an error. Link to comment Share on other sites More sharing options...
Synook Posted November 14, 2007 Share Posted November 14, 2007 we forgot the .value propertyif (the_dot == frm.user_email.value.length -1){ Link to comment Share on other sites More sharing options...
Praetorian Posted November 14, 2007 Author Share Posted November 14, 2007 Gah. I'm stupid. I remembered to add it to the var part, but forgot to add it to the function. Sheesh. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.