1

I have a form which I would like to validate certain fields as being required as well as being digits. I'm having trouble figuring out how to apply both rules to said fields.

Currently here is how I am applying only the required rule, displaying the message in a span I have built into my form.

    if (jQuery.validator) {
    jQuery.validator.setDefaults({
        errorPlacement: function (error, element) {
            error.appendTo('#invalid-' + element.attr('id'));
        }
    });
}

$("#UserInputs").validate();


<label for="AvgGroupSize">Average Group Size:</label><br />
<span id="invalid-AvgGroupSize"></span>
<input type='text' id='AvgGroupSize' class='required' size='4' value='15'/> EEA's

How would I able to add a second validation rule (digits) to this field?

Thank you.

2
  • class='required digits' isn't working? Commented Nov 12, 2012 at 21:59
  • It does work, I didn't realize that was an option. Thank you. Commented Nov 13, 2012 at 14:39

1 Answer 1

1

You just need to add a class to your input:
<input type='text' id='AvgGroupSize' class='required digits' size='4' value='15'/> EEA's

if digits validation class doesn't exist yet you need to add i through: Add Class Rules

Another option might be is just adding rules to your input.

something like this:

$("#AvgGroupSize").rules("add", {
 minlength: 2
});

Read more on how to Add rule

Sign up to request clarification or add additional context in comments.

1 Comment

Great, I didn't even realize you could add multiple classes to elements in HTML, much less being able to do it with a jQuery plugin. Thanks a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.