Validating a date in javascript

Rated 3.97/5 based on 516 customer reviews

//-------------------------------------------------------------------------- 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 output will be almost identical to the earlier examples.

In this simple example we can even rewrite the In practice most modern browsers will now use HTML form validation to preempt any Java Script validation - with the notable exception of Safari. Visitors from some countries may find it confusing that we're using the and vice-versa as the year and day values have now changed position.

It does not check for leap years or invalid dates at the end of short months.

As we've seen before, creating re-usable functions can significantly reduce the size of your Java Script code.

Instead we're going to make use of Form Validation using Ajax to do some real-time checking using a server-side PHP script to get a definitive answer.

When you enter a date in the format dd/mm/yyyy the value is sent via an Ajax call to the server where it is validated using the PHP checkdate function.

I'm not going to show that here, but you can find a link to get started under References below. Solution: Tom Flynn from Sun Gard Higher Education provided the following Jave Script, which helped resolving the issue, so many thanks to Tom!function Validate Form(ctrl) //-------------------------------------------------------------------------- //This function verifies if the start date is prior to end date.By Tom Flynn, Sun Gard Higher Education, and Jeralee Seaburn, Hercules Tire Problem: Started in a Focal Point post, the question is, how to validate Date (calendar) controls in a guided ad-hoc HTML page?There have been so many problems with users not entering the date in mm/dd/yyyy, even when specifically stated on the screen.

Leave a Reply