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();   
   return false;
   return true;

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

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

 var emailReg  = /^([\w-\.][email protected]([\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");


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

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

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

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


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

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

    else if(!numberReg.test(telephone)){

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


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

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


      return facedError;  

2 thoughts on “Form validation using jQuery in php”

  1. Thank you a bunch for sharing this with all folks you actually understand what you’re
    speaking approximately! Bookmarked. Please additionally seek advice from
    my site =). We will have a link change arrangement among us

  2. Someone essentially help to make severely articles I might state.
    That is the first time I frequented your web page and up to now?
    I amazed with the research you made to create this particular put up extraordinary.
    Fantastic process!

Leave a Reply

Your email address will not be published. Required fields are marked *