Validating date in php

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.

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

Leave a Reply