Skip to content

plainDate

const plainDate: RegExp = /^(?:\d{4}|\+\d{6}|-(?!0{6})\d{6})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/;

RegExp matching ISO 8601 calendar date (extended): YYYY-MM-DD or ±YYYYYY-MM-DD.

import { plainDate } from "@northguild/gmt";
plainDate.test("2024-03-15") // true
plainDate.test("+000031-04-30") // true (6-digit year)
plainDate.test("-000031-04-30") // true (negative 6-digit year)
plainDate.exec("2024-03-15")?.slice(1) // ["03", "15"] (month, day)
plainDate.test("-000000-01-01") // false (negative zero year)
plainDate.test("2024-3-15") // false (unpadded month)
plainDate.test("2024-03-00") // false (day zero)

regex/date.ts