JavaScript Form Validation
<script language="javascript">
function verify() {
if (document.form1.name.value == "") {
alert("Please give the name");
document.form1.name.forus();
return false;
}
if (document.form1.email.value == "") {
alert("Please give the email");
return false;
}
if (document.form1.age.value == "") {
alert("Please give age");
document.form1.age.focus();
return false;
}
if (document.form1.age.value < 18 || document.form1.age.value > 60) {
alert("Please give Age range between 18 and 60");
document.form1.age.focus();
return false;
}
if (document.form1.gender[0].checked == false &&
document.form1.gender[1].checked == false) {
alert("Please select gender");
document.form1.gender.focus();
return false;
}
if (document.form1.language1.checked == false &&
document.form1.language2.checked == false &&
document.form1.language3.checked == false) {
alert("Please Select your choice of language(Atleast One)");
return false;
}
if (document.form1.country.value == "") {
alert("Please give country");
document.form1.country.focus();
return false;
}
if (document.form1.myaddress.value == "") {
alert("Please give address");
document.form1.myaddress.focus();
return false;
}
if (document.form1.u_name.value == "") {
alert("Please give username");
document.form1.u_name.focus();
return false;
}
if (document.form1.pass.value == "") {
alert("Please give Password");
document.form1.pass.focus();
return false;
}
if (document.form1.pass.value.lenght < 6) {
alert("Please give a Password more than 5 characters");
document.form1.pass.focus();
return false;
}
if (document.form1.r_pass.value == "") {
alert("Please retype your password");
document.form1.r_pass.focus();
return false;
}
if ((document.form1.pass.value) != (document.form1.r_pass.value)) {
alert("Your password does not match");
document.form1.r_pass.value == "";
document.form1.r_pass.focus();
return false;
}
return( true );
}
</script>
No comments:
Post a Comment
Thanks for your feedback