Regular expression validating date
You want to validate dates in the traditional formats mm/dd/yy, mm/dd/yyyy, dd/mm/yy, and dd/mm/yyyy.You want to use a simple regex that simply checks whether the input looks like a date, without trying to weed out things such as February 31You might think that something as conceptually trivial as a date should be an easy job for a regular expression. Because dates are such an everyday thing, humans are very sloppy with them. To somebody else, it may be the first working day of the year, if New Year’s Day is on a Friday.
We use alternation (see Recipe 2.8) inside a group to match various pairs of digits to form a range of two-digit numbers.
Now let’s jump to the regular expression itself: UK postal code examples : EC1A 1BB W1A 0AX M1 1AE B33 8TH CR2 6XH DN55 1PT So, 1 or 2 alphabetic characters, followed by 1 or 2 digits, then a space and one digit and exactly two alphabetic characters.