Task7 20bci021
Task7 20bci021
Code:
index.html
<head>
<title>Task 7</title>
</head>
<body>
<div class="container">
<h1>Form Validation</h1>
<form action="" method="get" id="form" name="details" onsubmit="return validate()">
<input class="color" type="text" name="name" id="name"
placeholder="Username*"><br>
<input class="color" type="password" name="pass" id="pass"
placeholder="Password*"><br>
<input class="color" type="date" name="date" id="date" placeholder="DOB*"><br>
<input class="color" type="email" name="mail" id="mail" placeholder="email*"><br>
<input class="color" type="number" name="mobile" id="mobile" placeholder="contact
number*"><br>
<div class="radio">
</div>
<br>
</div>
<br>
<br>
</form>
</div>
<script>
function validate(){
var m = document.getElementById("m");
var f = document.getElementById("f");
var o = document.getElementById("o");
var h = document.getElementById("hindi");
var e = document.getElementById("english");
var t = document.getElementById("tamil");
if(name.value.length == 0){
alert("name cannot be empty");
name.focus();
return false;
}
else if( !name.value.match(/^[A-Za-z]+$/)){
alert("name should be alphabet only");
name.focus();
return false;
}
else if(pass.value.length==0){
alert("passord cannot be empty");
pass.focus();
return false;
}
else if(!pass.value.match(/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$!&^*])[A-za-z\
d@#$!&^*]{8,}/)){
alert("Password should contain at least one upper case alphabet, a special character and
a number and should be at least 8 characters in length");
pass.focus();
return false;
}
else if(dob.value.length == 0){
alert("DOB cannot be empty");
dob.focus();
return false;
}
else if(email.value.length==0){
alert("mail cannot be empty");
email.focus();
return false;
}
else if(mobile.value.length!=10){
alert("Mobile should be of 10 digits");
mobile.focus();
return false;
}
</script>
</body>
</html>
Output Screenshot: