NOTICE

Adfly Links not working Find Direct Links HERE

jQuery Form Validation Email and Phone Number

HTML FORM
<form name="myform" method="get" action="business.php" onsubmit="">
Name<input type="text" id="id0" name="name[0]" value=""><div id="err0"></div><br>Email<input type="text" id="id1" name="name[1]" value=""><div id="err1"></div><br>Phone<input type="text" id="id2" name="name[2]" value=""><div id="err2"></div><br><input type="submit" onclick="checkValidit()">
</form>
jQuery Validation Code
<script type="text/javascript">
         function isValidEmailAddress(emailAddress) {
             var pattern = new RegExp(/^([w-.]+@([w-]+.)+[w-]{2,4})?$/);
             return pattern.test(emailAddress);
         };
         
         
         function isValidPhone(phone) {
             var pattern = new RegExp( /^d*[0-9](|.d*[0-9]|,d*[0-9])?$/);
             return pattern.test(phone);
         };
         
         function checkValidit()
         {
             if( !$("input").val() ) {
                 $("form").submit(function (e) {
                     e.preventDefault(); //prevent default form submit
                 });     
             }
         };
         
         
         
         
         $(function(){ 
             
             
             $('input').blur(function()
             {
                 if($(this).attr("id")=="id1")
                 {
                     // alert("email");
                     if( !isValidEmailAddress($(this).val()) ) 
                     {
                         $("#err1").html("Enter Valid Mail");
                     }else if(!$(this).val()){
                         $("#err1").html("Enter Mail");
                     }
                     else{
                         $("#err1").html("");
                     }
                     
                 }
                 else if($(this).attr("id")=="id2")
                 {
                     if( !isValidPhone($(this).val()) ) 
                     {
                         $("#err2").html("Enter Valid Phone");
                     }else if(!$(this).val()){
                         $("#err1").html("Enter Phone");
                     }
                     else{
                         $("#err2").html("");
                     }
                 }
                 else if($(this).attr("id")=="id0")
                 {
                     if( !$(this).val() ) 
                     {
                         $("#err0").html("Enter Name");
                     }
                     else{
                         $("#err0").html("");
                     }
                 }
             });
             
         });   
         
     </script>

0 comments :

Feel free to leave comment if you like above widget, have any questions or just say Hi! :)