How to validate a form with jQuery?

Posted by vlad on Stack Overflow See other posts from Stack Overflow or by vlad
Published on 2010-05-25T06:20:49Z Indexed on 2010/05/25 6:31 UTC
Read the original article Hit count: 255

Filed under:
|
|

I tried to find the answer in other questions but actually nothing worked -.- Somehow I hate JavaScript ... Anyway! My Code looks like:

function validate()
{
 if ($(":input").length == 0) 
 {
  $(":input").addClass("notvalid");
  return false;
 }
 else
 {
  $(":input").removeClass("notvalid");
  return true;
 } 

 return true;
}

$(":input").blur(validate());
$(":input").keyup(validate());

$("#customForm").submit(function(){
 if(validate()){
  return true;
 }
 else
 {
  return false;
 }
});

I just want to test every tag to be not empty. The test should be done when the focus is lost or after every key type. And of course after the submit button has been clicked.

It doesn't work. Firefox error console says something like: unknown pseudoclass or pseudoelement 'input'. What does this mean?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery