0

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!

1

2 Answers 2

3

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)
});
Sign up to request clarification or add additional context in comments.

Comments

1

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 .

1 Comment

if you could post your code it'll be easier to help you can you the

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.