Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
^(?'Year'(?:[2][0]|[1][9])(?:[0-9]{2,2}))(?'Month'(?:[0][1-9]|[1][0-2]))(?'Day'[0-2][1-9]|[3][0-1]|[1,2][0])$
/

Description

Very simple validation expression that will validate a date in the range of 19000101 through 20991231. These formats are very popular for partitioning and representing dates as Long values or Integers. This does not check for Leap year values, or the months with varying number of days.

Please Note: this will return a match on 20220231 even though this is not a valid date. Additional validations should be used if Leap years and Days of the Month should be verified as well.

Submitted by Edward Rush - 2 years ago