We help IT Professionals succeed at work.
Get Started

Need to up-date birth date validation javascript to check for valid date

Last Modified: 2013-11-19
I have the following javascript for validating a birth date:

function checkDate(myDate)
    re = /^\d{1,2}\-\d{1,2}\-\d{4}$/;
    return ( (myDate != '') && (!myDate.match(re)) );

However, .. this javascript function only verifies that the entered characters are numeric, and that they're in the format of "99-99-9999".  

I need to somehow update my function so that it also checks to verify that the entered date is valid, .. and  that it is NOT the current year OR or a year in the future (since the field is being used to enter people's birthdays).

For example, .. dates such as "13-32-2010" and "12-12-2011" should NOT be allowed.  Only valid calendar dates that are in a PAST YEAR should be allowed (ie: "06-11-2009").

( Before anyone suggests it -- we do NOT want to use a javascript-based calendar / datepicker.  The dates need to be manually entered. )

Can anyone here provide me with an updated javascript function that accomplishes the type of validation I've described?  Your help would be appreciated.  


- Yvan

Watch Question
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE