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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:21:59+00:00 2026-05-20T12:21:59+00:00

I am writing a form validator that needs to combine the values of three

  • 0

I am writing a form validator that needs to combine the values of three fields/drop downs into a string and check that string to see if it is a valid date. Currently, I am doing this by combining the values into a string of the form mm/dd/yyyy and running that string through a comparison:

// Value is a string like mm/dd/yyyy
var date = new Date(value);
if( !date_regex.test(value) || date.toString() == 'Invalid Date' ) {
    errors[element] = "Please provide a valid date";
}

This works fine in almost every case. In IE8, if the string is formed such that the month or day exceed the allowance for the given component, the date wraps them instead of marking the date as invalid. Examples:

string: 03//2011
should be valid: no
is valid: no
Date.toString(): Invalid Date
correct: yes

string: 03/10/2011
should be valid: yes
is valid: yes
Date.toString(): Wed Mar 10 00:00:00 PST 2010
correct: yes

string: 03/40/2011
should be valid: no
is valid: yes
Date.toString(): Fri Apr 9 00:00:00 PST 2010
correct: no

string: 20/05/2011
should be valid: no
is valid: yes
Date.toString(): Fri Aug 5 00:00:00 PST 2010
correct: no

I’ve tried using Date.parse(value) and checking for NaN, but the date wraps the timestamp, too.

Any ideas on how to get IE to behave like the others?

Thanks much

  • 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-20T12:21:59+00:00Added an answer on May 20, 2026 at 12:21 pm

    Convert the date object back into a string (by querying for the month,day,and year). If it matches what the user typed, then it’s likely valid.

    var year, month, day, compareString;
    
    var date = new Date(value);
    
    if( !date_regex.test(value) || date.toString() == 'Invalid Date' ) {
        errors[element] = "Please provide a valid date";
    }
    else {
    
        year = date.getFullYear().toString();
    
        month = (date.getMonth() >= 10) ? (date.getMonth().toString()) : ("0" + date.GetMonth().toString());
    
        day = (date.getMonth() >= 10) ? (date.getDate().toString()) : ("0" + date.GetDate().toString());
    
        compareString = month + "/" + day + "/" + year;
    
        if (compareString != value) // where "value" is what the user typed
            errors[element] = "Please provide a valid date";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a custom validator that is going to check for the existence of
I'm writing a form in XAML that has multiple buttons with content of different
I am writing an app which needs to have both the traditional form of
I have a PHP form that needs some very simple validation on submit. I'd
I am writing a more advanced file form element, more of a widget that
I have a form that has placeholders for input fields. It uses html5 placeholder
I'm writing a custom validator that checks that at least one field has a
I am writing a form to be inserted in clients' webpages that is to
I need to validate a form therefore I am writing a php class that
I have a strange problem with the validation I am writing on a form.

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.