<html> <script language = "JavaScript"> function checkName(text) { if(isNaN(text)){ return 1;} else{alert("Please enter a valid name. The only charachters accepted are A - Z and a - z");return 0;} } function checkAddress(text) { if(isNaN(text)){ return 1;} else{alert("Please enter a valid address. The only charachters accepted are A - Z and a - z");return 0;} } function validate(){ var Errortext=""; var emailID=document.form.email; var nn1=document.form.fname; var nn2=document.form.lname; var add=document.form.address; var gen=document.form.radios; var mobile=document.form.mobilenumber; var city=document.form.cityname; var state=document.form.statename; var zip=document.form.zip1; var password=document.form.pass; var cpassword=document.form.cpass; if(nn1.value == ""){ Errortext+="Please enter first name\n"; nn1.focus(); return false; } else if (checkName(nn1.value)==false){ nn1.value="" nn1.focus() return false } else if (nn2.value == ""){ Errortext+="please enter your name\n"; nn2.focus(); return false; } if (checkName(nn2.value)==false){ nn2.value="" nn2.focus() return false } else if ( (gen[0].checked == false ) && ( gen[1].checked == false ) ){ Errortext+="please check your gender: Female or Male\n"; gen[0].focus(); return false; } else if ((emailID.value == "" ||emailID.value.indexOf('@', 0) == -1) ||emailID.value.indexOf('.') == -1){ Errortext+="please enter proper email id\n"; emailID.focus(); return false; } else if(mobile.value=="") { Errortext+="please Enter the Contact Number\n"; mobile.focus(); return false; } else if(isNaN(mobile.value)||(mobile.value.length!=10)) { Errortext+="Enter the valid Mobile Number\n"; mobile.focus() return false } if(password.value==""){ Errortext+="password should be filled\n"; password.focus(); return false; } if(cpassword.value==""){ Errortext+="confirm password should be filled\n"; cpassword.focus() return false } if((cpassword.value=="")||(password.value!=cpassword.value)){ Errortext+="Please enter Password and confirm password and both should be same\n"; cpassword.focus() return false } if (add.value == ""){ Errortext+="Please enter address\n"; add.focus(); return false; } if (checkAddress(document.form.address.value)==false){ address.value="" address.focus() return false } if(city.value==""){ Errortext+="please enter your city\n"; city.focus(); return false; } if(state.value==""){ Errortext+="please enter your state\n"; state.focus(); return false; } if( zip.value == "" || isNaN(zip.value ) ||zip.value.length != 6 ){ Errortext+= "Please provide a zip in the format ######.\n"; zip.focus(); return false; } if(Errortext!=""){ alert( Errortext) return false; } return true } </script> <form name="form" onSubmit="return validate()"> <pre> First Name<input type="text" name="fname" id="fn" size="30"> Last Name<input type="text" name="lname" id="ln" size="30"> Gender<input type="radio" name="radios" value="male">Male <input type="radio" name="radios" value="Female">Female Enter an Email Address<input type="text" name="email" size="30"> Mobile Number<input type="text" name="mobilenumber"> Password<input type="password" name="pass"> Confirm Password<input type="password" name="cpass"> Address1<input type="text" name="address"> Address2<input type="text" name="add2"> Address3<input type="text" name="add3"> City<input type="text" name="cityname"> State<input type="text" name="statename"> ZIP<input type="text" name="zip1"> <input type="submit" name="Submit" value="Submit"> </pre></form> </html>
Ads