<!
DOCTYPE html>
<html>
<body>
<h2>HTML Forms</h2>
<script>
Function validation ()
Var a=document.getElementbyID(“uname”).value;
Var b= document.getElementbyID(“email”).value;
Var c= document.getElementbyID(“psd”).value;
Var d= document.getElementbyID(“cpsd”).value;
// validation condition to check all the field are filled
If (a==”” ||b==”” || c==”” ||d==””)
alert(“all the fields are mandatory”)
return false;
//validation the phone number shoulb be 10 digit only
else if (c.length>10 || c.length<10)
alert(“ number should be 10 digit only”)
return false;
//validation that phone number should be number only
else if(isNan(c))
Alert(“only number are allowed”)
Return false;
//validation to match the password and confirm password
Else if(c!=d)
Alert(“password should be same”)
return false;
Else
true; }
</script>
<form onsubmit= “return validation ()” action= “page2.html”>// action will render the page
on click to the page2.html if you want to redirect on the same page then call function with
return otherwise without return
<label for="uname">username</label><br>
<input type="text" id="uname" name="uname"><br>
<label for="email”>E=mail</label><br>
<input type="text" id="email" name="email" value= “[email protected]”><br><br>
<label for="password”>Password</label><br>
<input type="password" id="psd" name="pswd" value= “”><br><br>
<label for="cpsd”>ConfirmPassword</label><br>
<input type="password" id="cpsd" name="cpswd" value= “”><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>