javascript - why this regex "^(0[1-9]|1[0-9]|2[0-9]|3[01])/(0[1-9]|1[012])/(19[0-9]{2}|20[0-1][0-7])$" fails for dates like 16/06/2008, 21/02/2008..? -


i trying match dates starting year 1900 2017 in dd/mm/yyyy format using

^(0[1-9]|1[0-9]|2[0-9]|3[01])/(0[1-9]|1[012])/(19[0-9]{2}|20[0-1][0-7])$ 

regular expression observing regular expression fails dates 16/06/2008 , 21/02/2008.
make sure parts of regular expression working or not tried 3 parts ^(0[1-9]|1[0-9]|2[0-9]|3[01])$ , ^(0[1-9]|1[012])$ , ^(19[0-9]{2}|20[0-1][0-7])$ on different sets of days months , years found these working fine when ran combined got same unexpected result date 16/06/2008.

additionally want inform using regex in javascript :

var patt = new regexp("^(0[1-9]|1[0-9]|2[0-9]|3[01])/(0[1-9]|1[012])/(19[0-9]{2}|20[0-1][0-7])$"); var res = patt.exec(datestring); 

for dates 16/06/2008 res evaluates null.

please let me know going wrong i? solve have gone through regular expression tutorials , asked questions did not find relavent answer can tell me why regex fails specific dates. please help.

along with

20[0-1][0-7] 

not matching year 2008 (8 not fall in range [0-7]) may want escape forward slashes in regex using backslash below

^(0[1-9]|1[0-9]|2[0-9]|3[01])\/(0[1-9]|1[012])\/(19[0-9]{2}|20[0-1][0-9])$ 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -