Pages

Validatinng date with regular expression

Regular expressions are sequence or pattern of characters . They provide the foundation for pattern-matching functionality. He is a example of how to validate date with regular expression.

Condition:
Date d/m/yy and dd/mm/yyyy
1/1/00 through 31/12/99 and 01/01/1900 through 31/12/2099
Matches invalid dates such as February 31st
'\b(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)?[0-9]{2}\b'
Condition:
Date dd/mm/yyyy
01/01/1900 through 31/12/2099
Matches invalid dates such as February 31st
'(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}'
Condition:
Date m/d/y and mm/dd/yyyy
1/1/99 through 12/31/99 and 01/01/1900 through 12/31/2099
Matches invalid dates such as February 31st
Accepts dashes, spaces, forward slashes and dots as date separators
'\b(0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2}\b'
Condition:
Date mm/dd/yyyy
01/01/1900 through 12/31/2099
Matches invalid dates such as February 31st
'(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)[0-9]{2}'
Condition:
Date yy-m-d or yyyy-mm-dd
00-1-1 through 99-12-31 and 1900-01-01 through 2099-12-31
Matches invalid dates such as February 31st
'\b(19|20)?[0-9]{2}[- /.](0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])\b'
Condition:
Date yyyy-mm-dd
1900-01-01 through 2099-12-31
Matches invalid dates such as February 31st
'(19|20)[0-9]{2}[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])'