Regular Expression to Validate Date Formats

Description


Within PaperVision Capture, regular expressions can be used to validate batch names and index fields populated by a user or an OCR process. Below are a few regular expressions that validate some common date formats:

Summary


Format 1:

MM/DD/YY HH:MM AM/PM

Regular Expressions:

^([0]d|[1][0-2])/([0-2]d|[3][0-1])/([2][01]|[1][6-9])d{2}(s([0]d|[1][0-2])(:[0-5]d){1,2})*s*([aApP][mM]{0,2})?$

Example:

12/31/2002   | 12/31/2002 08:00 |  12/31/2002 08:00 AM

Format 2:

DD/MM/YYYY HH:MM AM/PM

Regular Expressions:

(?n:^(?=d)((?<day>31(?!(.0?[2469]|11))|30(?!.0?2)|29(?(.0?2)(?=.{3,4}(1[6-9]|[2-9]d)(0[48]|[2468][048]|[13579][26])|(16|[2468][048]|[3579][26])00))|0?[1-9]|1d|2[0-8])(?<sep>[/.-])(?<month>0?[1-9]|1[012])2(?<year>(1[6-9]|[2-9]d)d{2})(?:(?=x20d)x20|$))?(?<time>((0?[1-9]|1[012])(:[0-5]d){0,2}(?i: [AP]M))|([01]d|2[0-3])(:[0-5]d){1,2})?$)

Example:

31/12/2002   | 31/12/2002 08:00 |  31/12/2002 08:00 AM

Format 3:

YYYY/MM/DD HH:MM:SS

Regular Expressions:

^([2][0]d{2}/([0]d|[1][0-2])/([0-2]d|[3][0-1]))$|^([2][0]d{2}/([0]d|[1][0-2])/([0-2]d|[3][0-1])s([0-1]d|[2][0-3]):[0-5]d:[0-5]d)$

Example:

2002/02/03   | 2002/02/03 12:12:18

 

Filed under PaperVision® Capture, R71.1

Last modified Jul 01, 2010

Submitted Jul 01, 2010

Related Articles

Share via Email Print