Wednesday, March 15, 2017

Easy RegEx To Validate Dates in MMDDYY Format

This RexEx will validate dates in the format MMDDYY including leap year. I get a lot of dates from mainframe files and this is one of their favorite formats.

^0[13578]([012][0-9]|3[0-1])[12][0-9]$|^1[02]([012][0-9]|3[0-1])[12][0-9]$|^0[469]([012][0-9]|30)[12][0-9]$|^02([01][0-9]|2[0-8])[12][0-9]$|^0229[02][048]$|^02291[26]$

Caveats:

  • Only works for dates from 2010 thru 2029
  • Notice that the century is missing

No comments:

Post a Comment