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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another form question 1

Status
Not open for further replies.

tnbrwneyez

Programmer
Oct 2, 2004
19
US
I need to take the following code and add a text field for an email address. I need to add a feature to the validate function that verifies that the email address is at least 5 characters and that it contains @ symbol.
<html>
<head>
<title>Form Example</title>
<Script language="JavaScript" type="text/javascript">
function validate() {
if (document.form1.yourname.value.length < 1){
alert("Please enter your full name.");
return false;

}

if (document.form1.address.value.length < 3) {

alert("Please enter your address.");
return false;
}

if (document.form1.phone.value.length < 3) {
alert("Please enter your phone number.");
return false;

}

return true;

}

</script>

</head>
<body>
<h1>Form Example</h1>
<p>Enter the following information. When you press the Submit button, the date you entered will
be validated, then sent by email. </p>
<form name="form1" action="mailto:user@host.com" enctype="text/plain"
method"POST" onSubmit="return validate();">

<p><b>Name:</b> <input TYPE="Text" size="20" name="yourname">
</p>
<p><b>Address:</b> <input TYPE="Text" size="30" name="address">
</p>
<p><b>Phone:</b> <input TYPE="Text" size="15" name="phone">
</p>
<p><input TYPE="Submit" Value="Submit"> </p>
</form>
</body>
</html>

Thanks!
 
Code:
function isEmail(value)
{
  return (value.length >= 5 && value.test("/@/");
}

--Chessbot

"See the TURTLE of enormous girth!"
-- Stephen King, The Dark Tower series
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top