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 8082373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:04:24+00:00 2026-06-05T17:04:24+00:00

We have a form which uses the JQuery Validation Plugin and would like to

  • 0

We have a form which uses the JQuery Validation Plugin and would like to ignore any form field values which have not been changed from their default values.

For example, we have a credit card update form and only display the last four of the credit card number for security. It looks something like this:

**** 5629

This default value will be different for each user as the last four of their credit cards will be different.

If the user does not alter their default credit card value during their profile update, we’d like to bypass the validation routing on this form field as obviously it would not validate as a valid credit card number.

Here is our current validation snippet:

card_number: {
  required: true,
  creditcard: true
}

messages: {
  card_number: {
    required: "Please enter a <strong>valid credit card number</strong>.",       
  }

And here is the form field:

<input type="text" name="card_number" id="card_number" title="Your credit card number." value="************ 5629" />

How can we ignore validating any form field values which have not been changed from their default values?

Thanks.

===============================================

NEW NOTE TO ANDREW:

I think we’re running into a little glitch due to the way in which we are validating the credit card TYPE.

Here is the complete snippet along with your initial fix:

card_number: {
  creditcardtypes: function() {
    // return an object with a property named the same as the pay method
    var result = new Object();
    var propertyName = $('select[name="pay_method"]').val().toLowerCase();
    var propertyValue = 1;
    eval("result."+propertyName+"='"+propertyValue+"'");
    return result;
  },
  ccnotdefault: true,
  required: true
},

How can we also accommodate the credit card TYPE rule? Right now, validation fails because the default credit card value is not a valid credit card type.

Thanks again Andrew.

================================================

FORM FIELDS:

          <!--- PAYMENT METHOD FIELD --->
      <tr>
        <td style="padding-top:15px; text-align:right; width:45%;"><label for="pay_method">&nbsp;Payment Method:
          <span class="orderlineredsm"><strong> * </strong></span></label></td>
        <td style="padding-top:15px; text-align:left; width:55%;" colspan="2" align="left" id="pmethod">
          <select name="pay_method" id="pay_method" class="highlightme required" style="width: 115px;" onchange="jQuery('#card_number').valid()" title="Your Payment Method.">
              <option value="Visa" <cfif form.pay_method EQ "Visa">selected="selected"</cfif>>Visa</option>
              <option value="Mastercard" <cfif form.pay_method EQ "Mastercard">selected="selected"</cfif>>Mastercard</option>
              <option value="Amex" <cfif form.pay_method EQ "Amex">selected="selected"</cfif>>Amex</option>
              <option value="Discover" <cfif form.pay_method EQ "Discover">selected="selected"</cfif>>Discover</option>
              <option value="Diners" <cfif form.pay_method EQ "Diners">selected="selected"</cfif>>Diners</option>
          </select>
        </td>
      </tr>
      <!--- END PAYMENT METHOD FIELD --->

      <!--- CARD NUMBER FIELD --->
      <tr>
        <td style="text-align:right; width:45%;"><label for="card_number">&nbsp;Credit Card Number:
          <span class="orderlineredsm"><strong> * </strong></span></label></td>
        <td style="text-align:left; width:55%;" colspan="2" align="left" id="cnumber">
          <input type="text" name="card_number" id="card_number" class="highlightme" style="width: 130px;" maxlength="19" title="Your credit card number." value="************<cfoutput>#form.card_number#</cfoutput>" onfocus="clearText(this)" onblur="clearText(this)" />
          &nbsp;<span class="create-tooltip" title="For your protection and security, only the <strong>last four digits of your credit card number</strong> are shown.<br /><br /><strong>NOTE:</strong> Only change if you are updating your credit card number."><img src="/public/images/help_25.png" style="margin-bottom:1px;" alt="help" width="25" height="25" /></span>
        </td>
      </tr>
      <!--- CARD NUMBER FIELD --->

==========================================================

POSSIBLE FIX

card_number: {
  ccnotdefault: function(){ return $('#pay_method').val(); },
  required: true
},

jQuery.validator.addMethod("ccnotdefault", function(value, element, param) {
  // if the element is optional, don't validate 
  return this.optional(element) ||
  // or if the value is equal to the default value
  (value === element.defaultValue || 
  // or, finally, if the cc number is valid
  jQuery.validator.methods.creditcard2.call(this, value, element, param));
}, jQuery.validator.messages.creditcard);

http://www.ihwy.com/labs/downloads/jquery-validate-creditcard-2/jquery.validate.creditcard2-1.0.1.js
  • 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-05T17:04:27+00:00Added an answer on June 5, 2026 at 5:04 pm

    I would write a custom rule for this that calls the default credit card rule but also takes into account the default value of the field:

    $.validator.addMethod("ccnotdefault", function(value, element) {
        // if the element is optional, don't validate 
        return this.optional(element) ||
           // or if the value is equal to the default value
           (value === element.defaultValue || 
           // or, finally, if the cc number is valid
           $.validator.methods.creditcard.call(this, value, element));
    }, $.validator.messages.creditcard);
    
    $(document).ready(function() {
        $("#myform").validate({
            rules: {
                card_number: {
                    ccnotdefault: true,
                    required: true
                }
            }
        });
    });
    

    Example: http://jsbin.com/ejonid/2/

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

Sidebar

Related Questions

I have a form field which uses Jorn Zaefferer's autocomplete jQuery plugin. If i
I have a lengthy form which heavily uses client-side validation (written in jQuery). To
I have a form that uses the excellent jQuery validation plugin. This is a
I found this tutorial which uses jQuery and validation plugin to validate form input.
I have the following snippet, which uses the jQuery Form plugin to post a
I have a form which I am validating through the jQuery Validate plugin. Everything
I'm using the jQuery validation plugin and the form uses ajax to submit the
I'm building an app in CodeIgniter. I have an invoice form which uses jQuery
I have a simple contact form which uses jquery to post to a php
I have a live preview form: http://davidwalsh.name/jquery-comment-preview Which uses jquery to display the preview

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.