Skip to content

Instantly share code, notes, and snippets.

@bricss
Last active February 4, 2023 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bricss/b09714481adbaa607e387977eddf7761 to your computer and use it in GitHub Desktop.
Save bricss/b09714481adbaa607e387977eddf7761 to your computer and use it in GitHub Desktop.
RegExp for ISO 8601 date string validation
export const isoDateRex = /^(?:[-+]\d{2})?(?:\d{4}(?!\d{2}\b))(?:(-?)(?:(?:0[1-9]|1[0-2])(?:\1(?:[12]\d|0[1-9]|3[01]))?|W(?:[0-4]\d|5[0-2])(?:-?[1-7])?|(?:00[1-9]|0[1-9]\d|[12]\d{2}|3(?:[0-5]\d|6[1-6])))(?![T]$|[T][\d]+Z$)(?:[T\s](?:(?:(?:[01]\d|2[0-3])(?:(:?)[0-5]\d)?|24\:?00)(?:[.,]\d+(?!:))?)(?:\2[0-5]\d(?:[.,]\d+)?)?(?:[Z]|(?:[+-])(?:[01]\d|2[0-3])(?::?[0-5]\d)?)?)?)?$/;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment