2

to accept only numbers up to 31 (no 32, no 62, etc).

Currently works perfectly but if I type 50/80/1977 works anyway.

I need to validate the inputs DD MM YYYY. Any suggestion?

I don't want to use datapicker. and the number have to be in a UK format. DD/MM/YYYY.

the E.G. http://jsfiddle.net/davidesitua/bhdry/49/

DD77
  • 1,367
  • 2
  • 13
  • 25

1 Answers1

0

I wrote this function as an answer to another question, but I think it should do what you want -

function isValidDate(strDate) {
    if (strDate.length != 10) return false;
    var dateParts = strDate.split("/");
    var date = new Date(dateParts[2], (dateParts[1] - 1), dateParts[0]);
    if (date.getDate() == dateParts[0] && date.getMonth() == (dateParts[1] - 1) && date.getFullYear() == dateParts[2]) {
        return true;
    }
    else return false;
}

Demo - http://jsfiddle.net/2r6eX/2/

To use with your code, you could do something like -

if (!isValidDate(enteredDOB)) {
    $("#invalidDOB").fadeIn("slow");
    return false;
}    

Demo of code integrated with your code - http://jsfiddle.net/ScEuV/1/

Further solutions are given in the original question - How to check if a string is a legal "dd/mm/yyyy" date?

Community
  • 1
  • 1
ipr101
  • 24,096
  • 8
  • 59
  • 61
  • thanks, but I'm quite confused, could you update the code on http://jsfiddle.net/davidesitua/bhdry/49/ please? – DD77 Nov 25 '11 at 12:42
  • Just a note: I tried to provide future date and it says that I'm young but i doesn't even exist yet (if to believe to the date provided). – Vlad Stratulat Nov 28 '11 at 16:37