-1

I am attemtping to do validation via HTML5 pattern and regex. I want to only accept dates in the YYYY-MM-DD format. I tried to find one, and I found this: ([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])). However, when I test it, it accepts an empty input.

Could someone help me fix this please?

Thanks.

I T
  • 53
  • 1
  • 5

1 Answers1

0

This RegEx might help you to match your inputs:

[0-9]{4}-[0-9]{2}-[0-9]{2} 
Emma
  • 27,428
  • 11
  • 44
  • 69