1

Is there a jQuery validation rule to ensure that access_id is either 5, 6, or 8? I suppose I could create my own rule called inArray, but would rather use a supported rule if it exists.

{
   "rules":{
      "access_id":{
         "inArray":[5,6,8]
      }
   }
}


$.validator.addMethod("inArray", function(value, element, params) {
    return this.optional(element) || (value in params);
    }, "Not an allowed selection.");

1 Answer 1

1

Is there a jQuery validation rule to ensure that access_id is either 5, 6, or 8?

No, there is no such rule. You will need to write your own as you've already outlined.

In the future, you could simply look at the script and see the rules for yourself. The code comments on some of them explain usage. They're within the methods object towards the end of the script, and the additional-methods file is nothing but more rules.

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

1 Comment

Thanks Sparky, I did spend some time reviewing the existing rules. I was a little surprised that this one didn't exist. That being said, it is very easy to add a rule, so not a big deal.

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.