Form Validations Code
Form Validations Code
<html>
<head>
<script>
function check() {
var name =
document.forms.RegForm.Name.value;
var email =
document.forms.RegForm.EMail.value;
var phone =
document.forms.RegForm.Telephone.value;
var what =
document.forms.RegForm.Subject.value;
var password =
document.forms.RegForm.Password.value;
var address =
document.forms.RegForm.Address.value;
var regEmail=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/g;
//Javascript reGex for Email Validation.
var
regPhone=/^\d{10}$/; // Javascript reGex
for Phone Number validation.
var regName = /\d+$/g; //
Javascript reGex for Name validation
if (address == "") {
window.alert("Please enter your address.");
address.focus();
return false;
}
if (password == "") {
alert("Please enter your password");
password.focus();
return false;
}
Form validations:
if(password.length <6){
alert("Password should be atleast 6 character long");
password.focus();
return false;
}
if (phone == "" || !regPhone.test(phone)) {
alert("Please enter valid phone number.");
phone.focus();
return false;
}
if (what.selectedIndex == -1) {
alert("Please enter your course.");
what.focus();
return false;
}
return true;
}
</script>
<style>
div {
box-sizing: border-box;
width: 100%;
border: 100px solid black;
float: left;
align-content: center;
align-items: center;
}
form {
margin: 0 auto;
width: 600px;
}
</style>
</head>
<body>
<h1 style="text-align: center;">REGISTRATION FORM</h1>
<form name="RegForm" onsubmit="return check()" method="post">
<br />
Form validations:
<p>Address: <input type="text"
size="65" name="Address" />
</p>
<br />
<br />
<br />
<br />
<p>
SELECT YOUR COURSE
<select type="text" value="" name="Subject">
<option>BTECH</option>
<option>MTECH</option>
<option>PHD</option>
<option>MCA</option>
</select>
</p>
<br />
<br />
<p>
<input type="submit"
value="send" name="Submit" />
<input type="reset"
value="Reset" name="Reset" />
</p>
</form>
</body>
Form validations:
</html>