Skip to content

isISO8601 accepts impossible calendar dates (2021-02-30, 2021-04-31, 2021-02-29 in a non-leap year) #2940

Closed

Description

@philppplik

Describe the bug

isISO8601 checks the date components with a regex, so it rejects impossible months (00, 13) and day 00, but it does not verify that the day exists in the given month/year. Calendar-invalid dates pass:

const validator = require("validator"); // 13.15.35

validator.isISO8601("2021-02-30");        // => true (Feb has 28/29 days)
validator.isISO8601("2021-04-31");        // => true (Apr has 30 days)
validator.isISO8601("2021-02-29");        // => true (2021 is not a leap year)
validator.isISO8601("2021-13-01");        // => false (month 13 correctly rejected)
validator.isISO8601("2021-00-10");        // => false
validator.isISO8601("2021-02-00");        // => false

The library's own isDate disagrees:

validator.isDate("2021-02-30");           // => false
validator.isDate("2021-02-29");           // => false

ISO 8601 calendar dates are defined as valid Gregorian dates, so a 2021-02-30 is not a valid ISO 8601 date, and isISO8601 returning true for it makes the validator unreliable as a gate before parsing.

Note: #2841 covers the same problem for isRFC3339; this report is specifically about isISO8601, which still accepts these dates in 13.15.35.

Expected behavior

isISO8601("2021-02-30"), isISO8601("2021-04-31") and isISO8601("2021-02-29") (non-leap year) should return false.

Environment

  • validator.js: 13.15.35
  • Node.js: v22.23.3
  • OS: Linux

Activity

  1. philppplik commented on Oct 22, 2026

    @philppplik
    Author

    Withdrawn - my report is wrong. The README documents strict: false (the default) as syntax-only validation, and strict: true correctly rejects every example I gave:

    validator.isISO8601("2021-02-30", { strict: true }); // false
    validator.isISO8601("2021-04-31", { strict: true }); // false
    validator.isISO8601("2021-02-29", { strict: true }); // false
    validator.isISO8601("2020-02-29", { strict: true }); // true (valid leap day)

    So the behavior I described is the documented default mode, not a bug. Apologies for the noise - please feel free to close this.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions