-1

I want to validate date like 24-mar-2014 with java regular expression. but not able get correct regular expression.

Can someone please correct it.

\\d{2}-[a-z]-\\d{4}
Vinay Prajapati
  • 7,199
  • 9
  • 45
  • 86
Vikas Rajak
  • 49
  • 1
  • 1
  • 7

1 Answers1

1

Try

^(([0-9])|([0-2][0-9])|([3][0-1]))\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\-\d{4}$
Matteo Baldi
  • 5,613
  • 10
  • 39
  • 51
  • Please use a case-insenstive modfier - as it won't match OPs example as it is. And didn't java need double backslashes, like `\\d` – Sebastian Proske Mar 25 '16 at 10:38
  • @NikolasCharalambidis Yes, but if you try to validate a data with RegEx, and not allow stuff like `31st Feb`, or `29th` not on a leap year, it would be so long it would be completely impractical – Kaspar Lee Mar 25 '16 at 10:45
  • 1
    The answer is incomplete then. – Nikolas Charalambidis Mar 25 '16 at 10:47
  • @Druzion *"it would be so long it would be completely impractical"* That is why validating a date with a regex is a bad idea. – Tom Mar 25 '16 at 13:16