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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:44:57+00:00 2026-05-12T09:44:57+00:00

I’m making a form that I’m using the amazing JQuery validation plugin for (

  • 0

I’m making a form that I’m using the amazing JQuery validation plugin for (http://docs.jquery.com/Plugins/Validation/).

This form allows people to make donations and to specify if they will be paying by cheque or credit card. I use radio buttons to show either the credit card asp panel, or the cheque asp panel.

My rules and messages are all working. However, I wish to create a rule that avoids validating certain parts of the form (the creditcard panel) depending on another factor (the credit card panel’s visibility being set to ‘hidden’).

Please excuse the code I’m about to innundate you with – I stripped out most of the irrelevant parts, leaving in only those that demonstrate my methods of going about this.

My body_onload javascrip method:

function body_onload()
{
    document.getElementById('<%=Cheque.ClientID %>').style.display = 'none';
    document.getElementById('<%=CreditCard.ClientID %>').style.display = 'none';
}

My radio buttons to select a payment method:

<div style="width:430px; padding:5px;"><b>Payment Method:</b>&nbsp;&nbsp;
    <input type="radio" name="PaymentMethod" value="Cheque" onclick="ShowPaymentPanel(this.value)"/>Cheque &nbsp;&nbsp;&nbsp;<input type="radio" name="PaymentMethod" value="CreditCard" onclick="ShowPaymentPanel(this.value)"/>Credit Card</div>

And my lengthy validate method:

$(document).ready(function(){

        jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
            phone_number = phone_number.replace(/\s+/g, ""); 
            return this.optional(element) || phone_number.length > 9 &&
                phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
        }, "<br/>&nbsp;&nbsp;&nbsp;&nbsp;Please specify a valid phone number");

        // validate form on keyup and submit
        $("#TransactionForm").validate({
            rules: {
                FirstName: "required",
                LastName: "required",
                Phone: {
                    required: true,
                    phoneUS: true
                },
                CCName:{
                    required: true
                },
                CCNumber:{      
                    required: true,
                    creditcard: true
                },
                CCExpiry:{
                    required: true,
                    digits: true,
                    minlength: 4,   
                    maxlength: 4                    
                }
            },
            messages: {
                FirstName: "<br/>&nbsp;&nbsp;&nbsp;&nbsp;Required",
                LastName: "<br/>&nbsp;&nbsp;&nbsp;&nbsp;Required",
                Phone: {required: "<br/>&nbsp;&nbsp;&nbsp;&nbsp;Required"},
                CCName: "<br/>&nbsp;&nbsp;&nbsp;&nbsp;Please enter the name on the card",
                CCNumber: {
                    required: "<br/>&nbsp;&nbsp;&nbsp;&nbsp;Please enter the card number",
                    creditcard: "<br/>&nbsp;&nbsp;&nbsp;&nbsp;Please enter a valid card number"
                },
                CCExpiry:  {
                    required: "<br/>&nbsp;&nbsp;&nbsp;&nbsp;Please enter the expiry date",
                    minlength: "<br/>&nbsp;&nbsp;&nbsp;&nbsp;Please enter as MMYY",
                    maxlength: "<br/>&nbsp;&nbsp;&nbsp;&nbsp;Please enter as MMYY",
                    digits: "<br/>&nbsp;&nbsp;&nbsp;&nbsp;Date must be numeric"
                }
            }
        });
    });

Any help would be greatly appreciated!

  • 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-05-12T09:44:58+00:00Added an answer on May 12, 2026 at 9:44 am

    The validation plugin allows for this, for a required attribute you aren’t restricted to true/false, you can do this in your rules:

    CCNumber:{      
        required: "#<%=CreditCard.ClientID %>:visible",
        creditcard: "#<%=CreditCard.ClientID %>:visible"
    }
    

    Also, you can shorten your other syntax in the onload if you aren’t restricted for some reason:

    $(function() {
        $("#<%=Cheque.ClientID %>").hide();
        $("#<%=CreditCard.ClientID %>").hide();
    });
    

    However, I’d suggest applying a “hidden” css style to them to avoid any possible flicker, then just using the $("#<%=Cheque.ClientID %>").show(); syntax to show them when whatever you do triggers it. Whatever method you go with, then :visible selector will work, it acts exactly like it sounds.

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

Sidebar

Ask A Question

Stats

  • Questions 226k
  • Answers 226k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As I did not get anywhere after finding the comment… May 13, 2026 at 1:12 am
  • Editorial Team
    Editorial Team added an answer Not really Depending on how you have your .htaccess file… May 13, 2026 at 1:12 am
  • Editorial Team
    Editorial Team added an answer Doesn't look like there is a method for that in… May 13, 2026 at 1:12 am

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
In order to apply a triggered animation to all ToolTip s in my app,
I have a French site that I want to parse, but am running into

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.