Javascript for validating date in textbox

(You still need to check server-side, anyone can defeat client-side validation either knowingly or unwittingly.) -- Joe (Microsoft MVP - XML)my 2cents if I may - Why let the user enter a date, I always use a date picker pop up like most web sites do.users are used to this, date formats arnt an issue.....many things in the pro's list to go against IMO Wind is your friend Matt Hi Matt Well, i am using AJAX for date.Have tested it for the formats like: MM/dd/yyyy, dd/MM/yyyy, yyyy-MM-dd, yyyy. Note supplied date format and date string go hand in hand.Find in the below code which enables to perform the date validation for any of the supplied format to validate start/from and end/to dates.function button1_onclick(ctrl) //End function button1_onclick //This goes in the BODY portion of the HTML Add this phrase to any date control you want to call the function from: on Change="checkdate(this)" //We had to use onchange instead of onblur //because our call center software was interfering //with HTML code and causing the control to lose focus - // we ended up in an infinite loop of error messages.function is Valid Date(date) console.log(is Valid Date('')); console.log(is Valid Date('12/11/1961')); console.log(is Valid Date('')); console.log(is Valid Date('12/01/1961')); console.log(is Valid Date('')); console.log(is Valid Date('')); console.log(is Valid Date('')); It does fail though if you use only one digit for the month. Also, one digit for the day '01-1-2013' or if you use two digits for the year '01-01-13' Fyi, for future readers, you MUST also apply the following to your code for the above to work correctly.

javascript for validating date in textbox-30javascript for validating date in textbox-49javascript for validating date in textbox-58

The user can even enter things like "now" and "tomorrow" and it will be converted into a valid date.

There have been so many problems with users not entering the date in mm/dd/yyyy, even when specifically stated on the screen.

Solution: Tom Flynn from Sun Gard Higher Education provided the following Jave Script, which helped resolving the issue, so many thanks to Tom!

Here's the date JS library: and here's a j Query tip that I wrote: formats = ['MM-DD-YYYY', 'MM/DD/YYYY'] moment('11/28/1981', formats)Valid() // true moment('2-29-2003', formats)Valid() // false (not leap year) moment('2-29-2004', formats)Valid() // true (leap year) As I can find scarce little commentary on the matter, I would only use for dates covered by the Gregorian calendar.

There may be plugins for other (including historical or scientific) calendars.

Javascript for validating date in textbox