UNPKG

one-schema

Version:
11 lines (8 loc) 528 B
// https://www.myintervals.com/blog/2009/05/20/iso-8601-date-validation-that-doesnt-suck/ const iso8601Tester = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/; export default (input: string) => { if (typeof input !== 'string') { return false; } return iso8601Tester.test(input); };