regular expressions to check length with multiple options

date, regex

Solution

^(\d{1,2})\/(\d{1,2})\/(\d{2}|\d{4})$

Both `\d{2}{4}` and `\d{2|4}` are not correct regex expression. You have to do two digits and for digits separately and combine then using or: `(\d{2}|\d{4})`

Problem

I need to validate the date format, that can be either `11/11/11` or `11/22/2013`, i.e. the year block can be in `YY` or `YYYY` and the complete format will either `MM/DD/YY` or `MM/DD/YYYY` I've this code ``` ^(\d{1,2})\/(\d{1,2})\/(\d{4})$ ``` and I've tried ``` ^(\d{1,2})\/(\d{1,2})\/(\d{2}{4})$ // doesn't works, does nothing ``` and ``` ^(\d{1,2})\/(\d{1,2})\/(\d{2|4})$ // and it returns null every time ``` PS: I'm applying it with Javascript/jQuery

Original source