Freechatsex com - Validating a leap year

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').

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.

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.

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

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.