<HTML> <HEAD> <TITLE> Form Validation Example </TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- function validatePersonalInfo(){ var _first = document.info.fname.value; var _last = document.info.lname.value; var _street = document.info.street.value; var _city = document.info.city.value; var _zip = document.info.zip.value; var _phone = document.info.phone.value; var _email = document.info.email.value;
if(_first.toString() == ""){alert("Please enter a first name.");} if(_last.toString() == ""){alert("Please enter a last name.");} if(_street.toString() == ""){alert("Please enter your street name.");} if(_city.toString() == ""){alert("Please enter your city.");} if(_zip.toString() == ""){alert("Please enter your zip.");} if(_phone.toString() == ""){alert("Please enter your phone number.");} if(_email.toString() == ""){alert("Please enter your email.");}
var checkZip = checkNum(5); var phoneInput = document.info.phone.value; var validPhone = false; var validZip = false; if(checkZip == true){ validZip = true; } else{ alert("Invalid Zip Code" + validZip); } if(!checkPhone(phoneInput)){ alert("Phone number is invalid." + validPhone); } else{ validPhone = true; } if(validZip && validPhone){ alert("Your form has been verified"); } }
// Strips hyphens out of phone number and verifies that // phone number is valid. Any phone number in the format // xxxxxxxxxx, xxx-xxx-xxxx, or (xxx)xxx-xxxx will be valid