Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.2 kB
0
Indexable
Never
<!DOCTYPE HTML>
<HTML>
<HEAD>
 <TITLE> Form Validations </TITLE>
 <script type="text/javascript">
 var regex=null;
 function validate()
 {
 if(checkName() && checkAge() && checkEmail() && checkMobileNum())
 {
 alert("Valid Data");
 }
 else
 {
 alert("Invalid Data");
 }
 }
 function checkName()
 {
 var name=document.getElementById("name").value
 regex=/^[a-zA-Z]{1}[a-zA-Z0-9]{7,19}$/;
 return regex.test(name);
 }
function checkAge()

 {

 var age=document.getElementById("age").value;
 regex=/^[1-9]?[0-9]{1}$|^100$/;
 return regex.test(age);
 }
 function checkEmail()
 {
 var email=document.getElementById("email").value;
 regex=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
 return regex.test(email);
 }
 function checkMobileNum()
 {
 var mobilenum=document.getElementById("mobilenum").value;
 regex=/^(\+[\d]{1,5}|0)?[7-9]\d{9}$/;
 return regex.test(mobilenum);
 }
 </script>
</HEAD>
<BODY>
<form>
Name:<input type="text" id="name"><br>
Age:<input type="number" id="age"><br>
email-id:<input type="text" id="email"><br>
Mobile Number:<input type="number" id="mobilenum"><br>
<input type="submit" onClick="validate()">
<input type="reset">
</form>
</BODY>
</HTML>
Leave a Comment