For instance, “2015-02-30” is not a valid date but the Date instance would still be created.
The date will however be adjust to point to the next logical date and in this case, our Date will be set as “2015-03-02”.
Suppose now that we have the following text field in which we want to insert a date in dd-mm-yyyy format: As we can see, the regular expression evidenced in blue is use to control if inserted date follows or not the default assigned format.
If the pattern is valid then function proceed to the next step otherwise an error message is raised abd form is not sent (the regular expression guarantees moreover that date cannot be empty).
Dates in forms are inserted in two different ways, the first uses a text field where user type data following different patterns (in this tutorial we assume that dates are in dd-mm-yyyy format); the second uses instead pulldown menus.
Please download the premade validation script from here.