wow, thanks... there is a ton of info on regex... a little overwhelming for a newbie, but I've been reading up on it all day and I think I get it a little better now... but my script still isn't working right...
Code:
// Email Requirements function
var at = ("\@");
var firstLetter = /^([a-zA-Z_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var emailId = ("document.myForm.emailId.value");
function validEmail()
{
with (emailId)
{
if (document.myForm.emailId.value == "")
{
alert("Please enter a valid email")
myForm.emailId.focus();
return false;
}
if (at < 1 || at > 1)
{
alert("You have the wrong amount of @ symbols, Please enter a valid email");
myForm.emailId.focus();
return false;
}
if (firstLetter.test())
{
return addArray();
}
else
{
alert("Your email must begin with a letter, Please enter a valid email");
myForm.emailId.focus();
return false;
}
}
return addArray();
}
I'm not getting any browser errors, but the areas that will not work are while checking for the "@" and that the first character must be a letter. It completely ignores if you use more than one "@" and it will alert to enter a valid email whether or not the first character is a letter.
Also, I need to have the email field selected after the alert appears when there is an error. I tried myForm.emailId.focus.select(); but it gave me errors.
Bookmarks