Jump to content

Validating form


Praetorian

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...