Hello Universe
Hello Universe

Reputation: 3302

jquery validation denomination of price

I am using jquery validation. I need an input field to be number and Denominations of $250 only. The code i have for validation is

  rules: {
      myPrice: {
          required: true,
          number: true
      }

Now I need it be only denominations of $250. ???

Upvotes: 0

Views: 778

Answers (2)

iJade
iJade

Reputation: 23801

You need to add a new custom method to check if your price is in denomination of 250,hence simply add a new method using $.validator.addMethod

 $.validator.addMethod('denominationCheck', function (value) {
        return Number(value) % 250 == 0;
    }, '');

And in your rules modify as below

rules: {
  myPrice: {
      required: true,
      number: true,
      denominationCheck : 0
  }

Hope this helps

Upvotes: 3

stevemarvell
stevemarvell

Reputation: 993

$.validator.addMethod is what you're looking for

Upvotes: 1

Related Questions