Reputation: 23290
I’m using jQuery Validate for my site’s contact form. The input fields have pre-populated default values, i.e. “Name” is the default value for the text field where people should type their name.
Some of these fields are required, but the basic set-up of jQuery Validate only checks if there is content in the fields, not what the content is. My problem is that even if people don’t enter their name, the form will still validate because the default value of “Name” still exists in the field.
Does anyone know how I can program jQuery validate to check for the default values, and if they exist, to return an error message?
Thanks for the help!
Upvotes: 0
Views: 324
Reputation: 1959
I would use the valid = function(inputValue){ return true; }
From the docs
Set the values that are considered valid when the input is checked. The function returns true for valid input and false for invalid input.
So you would do something like
$('myform').validate({ valid: function(input){
// check input value against your default values
// - If match, return false (is NOT valid)
// - If no match, return true (is valid)
});
Upvotes: 3
Reputation: 816
This is a really good tutorial I've used to validate forms ajax style . http://roshanbh.com.np/2008/04/ajax-login-validation-php-jquery.html
It'll give you more control over what you validating .
Upvotes: 1