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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:00:23+00:00 2026-05-23T09:00:23+00:00

According to http://www.codingforums.com/archive/index.php/t-98569.html , the date validation could be done using the javascript’s date

  • 0

According to http://www.codingforums.com/archive/index.php/t-98569.html, the date validation could be done using the javascript’s date object.

I’ve a similar scenario, where I have individual year,month,date in seperate text boxes which get validated by regular expressions.Now I would like to leverage the JS’s date object to check stuff like days in a month and leap year validation which are not done by RegExp validation. But the stuff discussed in the above link doesn’t quite work for me.
For example,

<script type="text/javascript">
   var dy= new Date(2001,2,30);
   alert(dy.getFullYear()+" "+dy.getMonth()+" "+dy.getDate());
</script>

returns the date as it is. Shouldn’t dy.getMonth() return something like -1 to show that 30 days doesn’t exist in the month of February?. If this isn’t possible using Date object, please suggest some alternatives to validate the date.

Update:
I just found another link(http://internotredici.com/article/checkdateinjavascript/) which says the same.
PS:I am working on JS1.2 which is pretty old.

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

    You can make the date from the day, month, year bits, and then check that the bits are correct.

    function isvalid_mdy(s){
        var day, A= s.split(/\D+/).map(function(itm,i){return parseInt(itm,10)});
        A[0]-=1;
        try{
            day= new Date(A[2], A[0], A[1]);
            if(day.getMonth()== A[0] && day.getDate()== A[1]) return day;
            throw new Error('Bad Date ');
        }
        catch(er){
            return er.message;
        }
    }
    function isvalid_dmy(s){
        var day, A= s.split(/\D+/).map(function(itm,i){return parseInt(itm,10)});
        A[1]-=1;
        try{
            day= new Date(A[2], A[1], A[0]);
            if(day.getMonth()== A[1] && day.getDate()== A[0]) return day;
            throw new Error('Bad Date ');
        }
        catch(er){
            return er.message;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to http://www.codeguru.com/forum/showthread.php?t=463663 , C#'s getHashCode function in 3.5 is implemented as: public override
According to this http://www.cplusplus.com/reference/clibrary/csignal/signal.html SIGINT is generally used/cause by the user. How do i
According to google and some other sources (e.g., http://www.enterprisedt.com/publications/oracle/result_set.html ), if I want to
According to http://www.rebol.com/docs/core23/rebolcore-15.html You can use change/part to parse and replace but that doesn't
According to http://www.delphigroups.info/2/3/181838.html ( archive ) The preferred approach with ADO components is to
my site is all happily Gzipped according to: http://www.gidnetwork.com/tools/gzip-test.php However when I run it
According to http://www.html5samples.com/2010/03/html-5-canvas-the-2d-context-part-1/ This is the signature for the context.transform method context.transform(m11, m12, m21,
Just started using Apache Commons StringEscapeUtils . According to http://www.w3schools.com/tags/ref_entities.asp , &Ouml; should correspond
The following is the definition of copy, according to http://www.sgi.com/tech/stl/copy.html . template<class InputIterator, class
According to this: http://www.codeplex.com/IronPython/Wiki/View.aspx?title=IP20VsCPy25Perf&referringTitle=IronPython%20Performance IronPython (Python for .Net) is faster than regular Python (cPython)

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.