Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8947431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:45:34+00:00 2026-06-15T12:45:34+00:00

I have a custom jQuery validate rule called fiftyCents() where there are two rules:

  • 0

I have a custom jQuery validate rule called fiftyCents() where there are two rules:

  1. if the item is free, one can “buy” it for $0.00 or they can pay greater than $0.50.
  2. if the item is NOT free, then they must pay at least the cost specified (stored in a hidden cachedValue input field).

So those are my two validation error messages. The problem I’m having in adding these to fiftyCents() is that I can only figure out how to evaluate it as true/false and if false, display a single message, e.g., "Amount must be $0.00 OR greater than $0.50.".

The solution to the JSfiddle (code below too) appears to be to make a message object that could be part of the fiftyCents() function. However, I don’t know how to return that along with evaluating true/false. Thoughts?

JS:

$('button').click(function(){
  $('form').validate().form();
});
$.validator.addMethod("fiftyCents", function(value) {

  var cachedValue=$('.purchaseModalAmtPaidCached').val();
  var value = $('.purchaseModalAmtPaid').val();
  var message="Amount must be $0.00 OR greater than $0.50.";
  if(cachedValue>0) message='Amount must be at least'+cachedValue+'.';
  return cachedValue<=value && (value==0 || (0.51<=value && value<=10000));
}, message);   

$.validator.classRuleSettings.purchaseModalAmtPaid = { fiftyCents: true };

HTML:

 <form>
  <input  class="purchaseModalPassword required" minlength="8" type="password"name="password" value="dddddddv" title="Please enter a valid password"  />
  <input type="text"  title="Amount must be $0.00 OR greater than $0.50" 
  class="required purchaseModalAmtPaid" name="amt_paid" value="" />
  <input type="hidden" class='purchaseModalAmtPaidCached required' name="AmtPaidCached" value="0.00" /> 
  <button type='button'>Buy</button>
 </form>​
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:45:35+00:00Added an answer on June 15, 2026 at 12:45 pm

    Ok I answered my own question. What I ended up doing is splitting up the two rules into their own custom methods. I used an if/else before either custom method is invoked to determine which of the two should be followed.

    Here’s the JSFiddle and code below:

    JS:

    $('button').click(function(){
    $('form').validate().form();
    

    });

    var params=$('.purchaseModalAmtPaidCached').val();                   
    if(params>0){      
      $.validator.addMethod("AmountOrGreater", function(value, element, params) {
      console.log('amountOrGreater'+params[0]); 
      return params[0]<=value && (value==0 || (0.51<=value && value<=10000));
      }, $.validator.format("Amount must be at least {0}."));
      $.validator.classRuleSettings.purchaseModalAmtPaid = { AmountOrGreater: params };                       
    } 
    else{ 
      $.validator.addMethod("fiftyCents", function(value, element, params) {
      console.log('fiftyCents'+params[0]);
      return params[0]<=value && (value==0 || (0.51<=value && value<=10000));
      }, "Amount must be $0.00 OR greater than $0.50.");  
      $.validator.classRuleSettings.purchaseModalAmtPaid = { fiftyCents: params };  
    } //else
    

    HTML:

     <form>
      <input  class="purchaseModalPassword required" minlength="8" type="password" name="password" value="dddddddv" title="Please enter a valid password"  />
      <input type="text"   
    class="required purchaseModalAmtPaid" name="amt_paid" value=""  /> 
      <input type="hidden" class='purchaseModalAmtPaidCached required' name="AmtPaidCached" value="0.00" /> 
      <button type='button'>Buy</button>
    </form>​
    

    Note: A key to the HTML cooperating with jQuery validate is that if you give your inputs a title='' attribute then that title will always be used, thus overriding the message in your custom rule. This is relevant in my case b/c there were two custom rules/messages and I’m not able to determine in advance of the HTML being rendered which one the user would see.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using jQuery validation engine and I have two custom rules that I need
How do i select elements that have my custom data attribute data-validate with jQuery
I have created custom jQuery UI widget called uiPopover, very similar to UI-dialog (in
I have a weird bug with JQuery Validate and a custom method. For some
I have a custom rule: jQuery.validator.addMethod(greaterThanStartPrice, function(value, element, param) { return this.optional(element) || (parseFloat(value)
I really have no idea why my custom rule in jquery isnt working. all
Let's say I have a custom AddMethod to jQuery Validate like: $.validator.addMethod('min-length', function (val,
Is there a way to pass dynamic parameters into a custom jquery validate method?
I have a form that is using the jQuery validate functionality, with some custom
I am using the validate plugin for jquery and have the following custom method:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.