Validating date javascript accommodating employees religious beliefs

These functions can even be included from an external javascript file so that the browser can cache them, and so the programmer isn't always copying and pasting.In this case, we've created a stand-alone functions which will validate a date field: In each case the value passed to the function is the form field rather than the field value.

validating date javascript-29validating date javascript-79validating date javascript-73

The return value is displayed next to the input field: Other actions could also be taken such as disabling form submission until there is a valid date.

The relevant portions of the HTML are as follows: .

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.

When capturing information for insertion into a database, or use in other processing, it's important to control what the user can enter.

Otherwise you can end up with values in the database that have no relation to reality.

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.

Description: This script validates a date field to ensure it's in the format mm/dd/yyyy.

Tags: , ,