Checking date format

Sometimes you have to deal with an Infopath textfield to collect a date. Then it would be usefull to check if the date that is entered is a valid one.

This solution is not the perfect one, but it filters out most of the wrong answers and typo’s.

Click on “Validation” and add a new validation.

Enter this pattern in the pattern field. Make sure you select “does not compare to”

(([0-9])|([0-2][0-9])|(3[0-1]))\-(([1-9])|(0[1-9])|(1[0-2]))\-(([0-9][0-9])|([1-2][0,9][0-9][0-9]))
This checks for a european date (dd-mm-yyyy and d-m-yy or any combination)
An english version (MM/DD/YYYY) would be something like this: (([1-9])|(0[1-9])|(1[0-2]))\/(([0-9])|([0-2][0-9])|(3[0-1]))\/(([0-9][0-9])|([1-2][0,9][0-9][0-9]))