Date
Date regular expressions can be used to validate if a string has a valid date format and to extract a valid date from a string.
Simple date regex (DD/MM/YYYY)
Below is a simple regex to validate the string against a date format (D/M/YYYY or M/D/YYYY). This however does not guarantee that the date would be valid. You can also replace \\/ with a separator you need.
True
False
Enter a text in the input above to see the result
Example code in PHP:
ISO 8061 date regex (e.g. 2021-11-04T22:32:47.142354-10:00)
The ISO 8061 is an international standard for exchanging and serializing date and time data. For validating the format of ISO 8061 date and time and for extracting it a following regular expression could be used:
True
False
Enter a text in the input above to see the result
Example code in PHP:
True
False
Enter a text in the input above to see the result
Notes on date string regex validation
While there are some regular expressions that allow more complex date validations, it is usually better to validate dates using special date and time libraries. For example, in PHP DateTime::createFromFormat can be used for these purposes. In this case, the validation will look like this: