asp.net - Modify existing regex to only match dates with a year between 1900-2100 -
i have dates formatted in following format: 2008-01-01
my current regex (.net) is: ^((((1[6-9]|[2-9]\d)\d{2})-(0[13578]|1[02])-(0[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0[13456789]|1[012])-(0[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-02-(0[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-02-29))$
and handles dates fine. however, how change regex match dates years in between year 1900 , 2100?
try following one:
^((((19\d{2})|(20\d{2})|2100)-(0[13578]|1[02])-(0[1-9]|[12]\d|3[01]))| (((19\d{2})|(20\d{2})|2100)-(0[13456789]|1[012])-(0[1-9]|[12]\d|30))| (((19\d{2})|(20\d{2})|2100)-02-(0[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]| [2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-02-29))$
you can see working here.
Comments
Post a Comment