javascript - Trying to validate YYYY/MM/dd -
I know that there are so many regex threads, but I can not find anywhere.
I have a reggae that works well with the DJ / MM / YYYY format. Here it is:
^ ((0 [[13578] | 1 [02]) [\ /.] 31 [\ /.] [1- 9] [0- 9] { 3}). (([01,1] | [[3-9] | 1 [1-2]) [\ /.] (29 | 30) [. \ /] [1-9] [0-9] {3} ). (? (0 [1-9] | 1 [0-2]).? [\ /] (0 [1-9] | 1 [0-9] | 2 [0-8]) [\ /.] [1-9] [0-9] {3}). ([02,2] [./2/29] [./] (([1-9] [0-9] (04 | 08 | [2468] [048] | [13579] [26])). ([2468] [0] {3})) $
Example: 29/2 / 2014,31 / 4/2014 ...
but when I was trying to validate with YYYY / MM / DD format, I know it:
^ (((19 | 20 () [2468] [048] | [13,579] [26] | 0 [48]) | 2000) [\ /.] 02 [\ /.] 29 | ((19 | 20) [0-9] {2} [ \ /.] (0 [469] | | 11) [\ /.] (0 [1-9] |? [12] [0-9] | 30) | (19 | 20) [0-9] { 2} [\ /.] (0 [13578] |? 1 [02]) [\ /.] (0 [1-9] |? [12] [0-9] | 3 [01]) | (19 | 20) [0-9] {2} [\ /] 02 [\ /] (0 [1-9] | ..? 1 [0- 9] | 2 [0-8])) $
This pattern works only with YYYY: 1 9xx -> 20xxx.
When I change it Or, I hope that it can work well with YYYY: 1xxx -> 9xxx but it was not good.
I'm new to regex, and it is difficult to avoid. < / P>
Very bad and sorry for my bad English.
It is a bad idea to use regex to validate dates only due to leap year. I will use the pattern ^ \ d {4} / \ d {1,2} / \ d {1,2} $
in javascript, and more complete verification on the server side.
Comments
Post a Comment