Jquery- on Form Submit Validate

On Form Submit Validate using Jquery

<script type="text/javascript"> 
$(document).ready(function()
{ 
    $("#shr_form").on('submit', function()
    { 
       var dForm = $(this); 
       var damount  = dForm.find("input[name=damount]").val(); 
       var dMsgElmnt= dForm.find("#dmessage");
 
       dMsgElmnt.html(''); 
       dMsgElmnt.css('color',''); 

       if(damount=="") { 
          dMsgElmnt.css('color','red');
          dMsgElmnt.html("Please Enter a Minimum Amount."); 
          return false; 
       }else{ 
          var r = confirm("Do you want to submit?"); 
          if (r == true) 
          {     
             return true; 
          } else {    
              return false; 
          } 
       } 
    }) 
});
</script>
Please follow and like us:

Form validation using jQuery in php


## form validation in JQuery
<script type="text/javascript">

$(document).ready(function(){    $('#send_enquiry').click(function(){
var get_validate = validateForm();   
     console.log(get_validate);
if(get_validate>0){
   return false;
}else{
   return true;
}
});

 function validateForm(){
  var facedError = 0;
  var nameReg   = /^[A-Za-z]+$/;

  var numberReg =  /^[0-9]+$/;

 var emailReg  = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
  var names     = $('#fullname').val();

 var email     = $('#email').val();

 var telephone = $('#mobile').val();

 var message   = $('#message').val();

var inputVal = new Array(names, email, telephone, message);

 var inputMessage = new Array("Full Name","Email address", "Mobile number", "Message");

 $('.error').hide();

 if(inputVal[0] == ""){
     $('#fullnameLabel').after('<span class="error"> Please enter your ' + inputMessage[0] + '</span>');

      facedError++;
 } 
 else if(!nameReg.test(names)){  $('#fullnameLabel').after('<span class="error"> Letters only</span>');

  facedError++;
 }
 if(inputVal[1] == ""){
        $('#emailLabel').after('<span class="error"> Please enter your ' + inputMessage[1] + '</span>');

   facedError++;
 } 
 else if(!emailReg.test(email)){     $('#emailLabel').after('<span class="error"> Please enter a valid email address</span>');

   facedError++; 

   }
 if(inputVal[2] == ""){

$('#mobileLabel').after('<span class="error"> Please enter your ' + inputMessage[2] + '</span>');

        facedError++;
      } 
    else if(!numberReg.test(telephone)){

$('#mobileLabel').after('<span class="error"> Numbers only</span>');

        facedError++;
      }

 if(inputVal[3] == ""){

 $('#messageLabel').after('<span class="error"> Please enter your ' + inputMessage[3] + '</span>');

  facedError++;
      }

      return facedError;  
    }   
  });
</script>
Please follow and like us: