0

I have a relatively simple set of inputs that need correct validation, and I seem to have a hiccup so far. Upon clicking send, only the empty fields should be filled in with the .errorVal class to give them a red background. So that is the visual side of the validation. Also, I need these fields to have character validation. So, First and Last name cannot contain numbers. Email needs to have an @ symbol at some point. Any ideas?

http://jsbin.com/OlUGiXE/1/edit?html,css,js,output

$('.sendSupport').click(function () {
    if ($("table.forceCenter > input[type=text]:empty").length == 0 && $("textarea:empty").length == 0) {
        //alert('sent')
        $('.sentVal').fadeIn();
        $('.emptyVal').hide();
        // clear values
        $("input[type=text], textarea").val('').removeClass('errorVal');
    } else {
        //alert('empty')
        $('.emptyVal, .errorStar').fadeIn();
        $('.sentVal').hide();
        $("input[type=text]:empty, textarea:empty").addClass('errorVal');
    }
});
tshepang
  • 12,111
  • 21
  • 91
  • 136
triplethreat77
  • 1,276
  • 8
  • 34
  • 69

1 Answers1

0

To check if every input is not empty you can do something like this:

jQuery("input[type=text]").each(function() 
    {  

if($(this).val()=="")
 {
 $(this).addClass("errorVal");
}   

});

To check if an input have a number take a look at the link below:

Check whether an input string contains number

And if an input contains "@" read this Jquery check if input .val() contains certain characters

Community
  • 1
  • 1
Aditzu
  • 696
  • 1
  • 14
  • 25