Dev Helpers
← Back

Validate an ISO date

Validate an ISO date. A self-contained example using the JavaScript runtime.

Open this example in the interactive library

Source code

const valid = (s) =>
  /^\d{4}-\d{2}-\d{2}$/.test(s) &&
  !Number.isNaN(Date.parse(s)) &&
  new Date(s).toISOString().slice(0, 10) === s;
console.log(valid("2026-02-28"), valid("2026-02-30"));

Sample output

true false