Friday, 3 April 2015

Email_ validation and Phone _no _Validation in Javascript




<html>

<head>

<script type="text/javascript">


<!--
function validate()


{

   var emailID = document.myForm.EMail.value;
   atpos = emailID.indexOf("@");
   dotpos = emailID.lastIndexOf(".");
   if (atpos < 1 || ( dotpos - atpos < 2 ))
   {
       alert("Please enter correct email ID")
       document.myForm.EMail.focus() ;
       return false;
   }




if(document.myForm.phone.value=="")

{


alert("Please enter  phone  no")

       document.myForm.phone.focus() ;


return false;

}


if(document.myForm.phone.value.length>10)


{

alert("Please enter 10 digit mobile number  only phone")

       document.myForm.phone.focus() ;


return false;


}

if(document.myForm.phone.value.length<10)


{

alert("Please enter 10 digit mobile number  only phone")

       document.myForm.phone.focus() ;


return false;


}



if(isNaN(document.myForm.phone.value))
{


alert("Please enter correct phone")

       document.myForm.phone.focus() ;


return false;


}


return true;


}

//-->


</script>



</head>



<body>

<form action="" name="myForm"   onsubmit="return(validate());">

email<input type=text name="EMail"  id="EMail"  value="">

phone <input type=text name="phone"  id="phone"  value="">

<input type="submit" name="submit"  value="submit">

</form>

</body>

</html>

No comments:

Post a Comment