Javascript code for validating date format

//-------------------------------------------------------------------------- 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 expressions use a pre-defined class is returned which enables the form to be submitted.

This routine DOES NOT check that the date or time input values are valid, just that they match the required format (d/m/y and h:m). Once you're in control of the input format, it's a lot easier to check that the values are actually valid.

The function has been improved now so that the day, month and year values are checked to ensure that they're in the right ball-bark (ie. Also the year must be between 1902 and the current year.

//Begin function checkdate function checkdate(input) //Begin function button1_onclick //This makes sure that even if it somehow got past the original error check, //the report won't run unless the date format is correct.

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.

Search for javascript code for validating date format:

javascript code for validating date format-41

The code behind the form now is as follows: If you're not already familiar with regular expressions, then this might be getting a bit complicated.

Leave a Reply

Your email address will not be published. Required fields are marked *

One thought on “javascript code for validating date format”