Validating a leap year

If the first two characters of the third element in the array that was created by the split, meaning just the four digits for the year, if they are not either 19 or 20 then the test is false. i found this on "any year divisible by 4 except centenary years not divisible by 400" and also: "A year in the Gregorian calendar having 366 days, with the extra day, February 29, intercalated to compensate for the quarter-day difference between an ordinary year and the astronomical year."... Does javascript have classes already built to handle this sort of thing ?

validating a leap year-76

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.

In Java Script to check for different month lengths, particularly for February in leap years, you need quite a bit of extra code.

I'm not going to show that here, but you can find a link to get started under References below.

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.

In this example, the date fields will only accept input that matches the pattern 'dd/mm/yyyy' (this could just as easily be changed to 'yyyy-mm-dd' or 'mm/dd/yyyy').

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.

Similar to this setup from another example: With Ajax you can make use of more powerful server-side functions and don't have to include large Java Script libraries for validating dates and other values.

Tags: , ,