Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Validation Issue 1

Status
Not open for further replies.

meldrape

Programmer
May 12, 2001
516
0
16
US
Greetings, I have the following code I'm using for email validation. It works flawlessly. BUT now I need to add a validation for firstname and lastname that if they are blank they get an error message. I've been jacking around with this for an hour and can't figure it out. Any help would be appreciated. THanks in advance.

Code:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function checkEmail(myForm) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value)){
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}
//  End -->
</script>
 
Code:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function checkEmail(myForm) {
if (myForm.firstname.value == ""){
 alert("Enter your First Name");
 myForm.firstname.focis();
 return false:}

if (myForm.lastname.value == ""){
 alert("Enter your Last Name");
 myForm.lastname.focis();
 return false:}

if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value)){
return (true)
}
alert("Invalid E-mail Address! Please re-enter.")
return (false)
}
//  End -->
</script>

There's always a better way.  The fun is trying to find it!
 
Thanks tviman. I replaced my code with your code. Now I'm getting an error:

Line 10
Error: expected ';'

I know very little about javascript. I have no idea which line 10 or where to put the ';'.

Any thoughts? Thanks again!
 
his
return false:}

must be:
return false;}



Known is handfull, Unknown is worldfull
 
Oops... sorry for the typo.

There's always a better way. The fun is trying to find it!
 
That's ok tviman. If I knew more about javascript, I probably would have figured it out!! Anyway, I used your solution and it works great. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top