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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:36:19+00:00 2026-05-13T20:36:19+00:00

On my client registration form I have the following rules // Define the div

  • 0

On my client registration form I have the following rules

// Define the div containing validation messages
var container = $('#clientErrorWrapper');
// Start validation routine 
// validate the form when it is submitted
var validator = $("#frmEdit").submit(function() {
    // update underlying textarea before submit validation
    tinyMCE.triggerSave();
    }).validate({
    errorContainer: container,
    errorLabelContainer: $("ul", container),
    wrapper: 'li',
    // start rules (add new rules as necessary)
        rules: {
            firstname: {
                required: true
            },
            lastname: {
                required: true
            },
            email: {
                required: true
            },
            address1: {
                required: true
            },
            city: {
                required: true
            },
            state_province: {
                required: function(element) {
                    return $("#country").val() == 'US';
                  }
            },
            postcode: {
                required: true
            },
            country: {
                required: true
            }
    // finish rules
    }

I would like to extend the state_province rules so that this field is required if country equals CA or AU as well, how can I achieve this please.

  • 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-13T20:36:19+00:00Added an answer on May 13, 2026 at 8:36 pm

    You can do:

            state_province: {
                required: function(element) {
                    var c = $("#country").val();
                    return c=='US' || c=='CA' || c=='AU';
                  }
            }
    

    No need to get more complicated than that unless your list gets a bit longer.

    If however the list grows, you can use jQuery’s .inArray():

            state_province: {
                required: function(element) {
                    return $.inArray($("#country").val(), ['US','CA','AU']) > -1;
                  }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating registration page and I've done basic client side (JS) form validation. Now
Instead of asking a client timezone in registration form (to correctly format datetime, all
I have a 3-part registration form using PHP: page 1 : collects info -
I have one registration form, I don't want people to register login username with
I am Developing a Registration Form in ASP.NET in Which I am using client
I have an interface for Client Registration called IRegistrationService. This contains one method called
We have to build an event registration website for our client in ASP.NET using
I can't seem to get client side validation working with the version of MVC
I'm writing a project where after registration I save id of each client in
I have a client who would like to have drop down list added to

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.