0

I have a date field that takes a date with the "dd/MM/yyy" format or "yyyy". So I used this regex:

REGEX_DATE = "^((([0]{1}[1-9]{1})|([1-2]{1}[0-9]{1})|([3]{1}[0-1]{1}))"
            + "/(([0]{1}[1-9]{1})|([1]{1}[0-2]{1}))/([0-9]{4}))"
            + "|(([1]{1}([9]{1})[1-9]{1}[0-9]{1}))"
            + "|(([2]{1}([0-9]{3}))) "
            + "|^((([0]{1}[1-9]{1})|([1-2]{1}[0-9]{1})|([3]{1}[0-1]{1}))(([0]{1}[1-9]{1})|([1]{1}[0-2]{1}))([0-9]{4}))"
            + "|^$";

But the dates with the format "yyyy" are not working. Where is my mistake?

Thanks!

Chris
  • 107
  • 1
  • 1
  • 8

1 Answers1

0

Can't you use this:

((0[0-9]|1[0-2])\/([0-2][0-9]|3[0-1])\/)?\d{4}
jcuenod
  • 55,835
  • 14
  • 65
  • 102