Validating a date in javascript

Rated 3.85/5 based on 794 customer reviews

First, formatting: 25/2/2011 is a perfectly good date in much of Europe. Second: if you want it to work historically, there are ancient leaders who invalidated certain dates by messing with the calendar. You can also test the bits of the date string: You should think otherwise, the function I posted only needs to check the month.

The time field will allow input starting with 'hh:mm' following by an optional 'am' or 'pm'. The code behind the form is as follows: For each field in the form (first the dates, then the time field), a check is made as to whether the input is blank.

//-------------------------------------------------------------------------- function check Entered Dates(stdateval,endateval) //-------------------------------------------------------------------------- //This function validates the date for MM/DD/YYYY format.

//-------------------------------------------------------------------------- function is Valid Date(date Str) //These functions go between the tags.

The year limitation would be used if you were asking for a date of birth or date of some recent event.

If you're setting up a calendar of future events you would check that the year is the current year or greater.

Leave a Reply