Skip to content

Instantly share code, notes, and snippets.

@xacnio
Created February 20, 2023 11:52
Show Gist options
  • Save xacnio/549846d69740a9038edf9421b3e9eb19 to your computer and use it in GitHub Desktop.
Save xacnio/549846d69740a9038edf9421b3e9eb19 to your computer and use it in GitHub Desktop.
Date regex validate - turkish month names

Regex Pattern

^(?:(?:31(\/|-|\.|\ )(?:0?[13578]|1[02]|(?:Ocak|Mart|Mayıs|Temmuz|Ağustos|Ekim|Aralık)))\1|(?:(?:29|30)(\/|-|\.|\ )(?:0?[1,3-9]|1[0-2]|(?:Ocak|Mart|Nisan|Mayıs|Haziran|Temmuz|Ağustos|Eylül|Ekim|Kasım|Aralık))\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.|\ )(?:0?2|(?:Şubat))\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.|\ )(?:(?:0?[1-9]|(?:Ocak|Şubat|Mart|Nisan|Mayıs|Haziran|Temmuz|Ağustos|Eylül))|(?:1[0-2]|(?:Ekim|Kasım|Aralık)))\4(?:(?:1[6-9]|[2-9]\d)\d{2})$
  • Validating date (Validating with months' maximum days, checking year for february checking)
  • Multiple separators
  • Month names

Source

https://stackoverflow.com/a/26972181

Examples

  • Separators: space - , /
  • 01 Ocak 1990
  • 01.01.1990
  • 01/01/1990
  • 01-01-1990
  • 1-1-1990
  • 1-Ocak-1990
  • ...
  • ...

Regexper Visualize

image (1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment