Javascript code for validating date

Posted by / 14-Aug-2016 20:25

Javascript code for validating date

//-------------------------------------------------------------------------- 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.

If not, the input is compared to the regular expression.

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.

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.

Basically, for each of the regular expression tests, an array is returned holding each component of the pattern that we've matched.

Each of these values is then tested against an allowed range (days: 1 - 31; months: 1 - 12; years: 1902 - 2017; and so on).

This script only confirms that the input format is correct and that each individual value falls within its allowed range.

If the valid date character is changed please make sure you replace it in the HTML and Javascript code too.

Now the date string is seperated into the month, day and year integers.

javascript code for validating date-31javascript code for validating date-57javascript code for validating date-17

//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.