0% found this document useful (0 votes)
23 views

Form Validation

The document contains HTML code for a form that validates user input. The form collects a name, age, and email address. JavaScript validation checks that the name is less than 10 characters, age is a number from 1 to 100, and email contains an @ symbol.

Uploaded by

fuzel jamil
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Form Validation

The document contains HTML code for a form that validates user input. The form collects a name, age, and email address. JavaScript validation checks that the name is less than 10 characters, age is a number from 1 to 100, and email contains an @ symbol.

Uploaded by

fuzel jamil
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

<html>

<head>
<script type="text/javascript">
function validate()
{
var at=document.getElementById("email").value.indexOf("@");
var age=document.getElementById("age").value;
var fname=document.getElementById("fname").value;
submitOK="true";

if (fname.length>10)
{
alert("The name may have no more than 10 characters");
submitOK="false";
}
if (isNaN(age)||age<1||age>100)
{
alert("The age must be a number between 1 and 100");
submitOK="false";
}
if (at==-1)
{
alert("Not a valid e-mail!");
submitOK="false";
}
if (submitOK=="false")
{
return false;
}
}
</script>
</head>

<body>
<form action="tryjs_submitpage.htm" onsubmit="return validate()">
Name (max 10 characters): <input type="text" id="fname" size="20"><br />
Age (from 1 to 100): <input type="text" id="age" size="20"><br />
E-mail: <input type="text" id="email" size="20"><br />
<br />
<input type="submit" value="Submit">
</form>
</body>

</html>

You might also like