Regex To Match A Valid Day In A Date String

A regular expression to match a valid day in a date string (from 1 to 31).

/(0[1-9]|[12]\d|3[01])/g

Matches:

  • 01
  • 31
  • 29

Use this regex instead if you don’t want days with a preceding zero.

/([1-9]|[12]\d|3[01])/g

Matches:

  • 1
  • 31
  • 29

See Also: