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

  • Home
  • SEARCH
  • 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 897409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:53:03+00:00 2026-05-15T14:53:03+00:00

In the jQuery Validation plugin there are a couple of methods that do the

  • 0

In the jQuery Validation plugin there are a couple of methods that do the same thing, but for different locales, for example dateISO and dateDE, that both validate date formatting. How do I combine these so that the input element accepts either?

Let’s say I have an <input type="text" name="dateInput" id="dateInput" /> in my form, and I want to allow users to enter only dates in this field. However, I want to allow for several different date formats – for example, the user should be able to enter either an ISO date or a date formatted accoding to German date rules.

If I do

rules: { dateInput: { required: true, dateISO: true, dateDE: true } }

the form will never be valid, as both date formats will be required and that requirement can never be fulfilled. Is there a way to combine these as an “or” instead of as an “and”, without having to write my own validation method?

And if I do have to write my own, how do I make it as generic as possible?

  • 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-15T14:53:04+00:00Added an answer on May 15, 2026 at 2:53 pm

    While you can combine the regexes like Reigel has, you can also just call those methods directly (in case they change!), like this:

    $.validator.addMethod("dateISODE", function(value, element) { 
        return $.validator.methods.dateISO.apply(this, arguments) 
            || $.validator.methods.date.apply(this, arguments); 
    }, "Please enter a valid ISO or German date");
    

    Now I have date instead of dateDE here, because in newer versions of the plugin dateDE was removed. It’s now in a localization file that just overrides the date method. If you’re using an older version that’s fine, just stick with dateDE.

    You can try a demo here


    Update for comments: A more generic form would look like this:

    $.validator.addMethod("oneOf", function(value, element, params) {
      for(p in params) {
        if(params.hasOwnProperty(p) && 
           $.validator.methods[p].apply(this, [value, element, params[p]]))
          return true;
      }
      return false;
    }, "Please enter a valid date");
    

    The rules would look like this:

    $("form").validate({
      rules: {
        dateFieldName: { oneOf: { dateISO:true, date:true } }
      }
    });
    

    You can try a demo here, this takes any number of validator functions and runs them, at least one must return true for it to succeed.

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

Sidebar

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.