admin-ch / CovidCertificate-Apidoc

API documentation for the integration of primary systems with the machine to machine API
73 stars 7 forks source link

Error in regexp for dateOfBirth validation #4

Closed ypiguet-epfl closed 3 years ago

ypiguet-epfl commented 3 years ago

The regexp suggested to validate dateOfBirth, vaccinationDate, and dateOfFirstPositiveTestResult, has at least 3 errors:

Suggestion: Use the following regexp: "^(19|20)[0-9][0-9]-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|30|31)$".

fabianegli commented 3 years ago

Regex is not the right tool to validate date inputs. Some calendar/date utility should be used instead.

A simple regex will fail for example for leap days: "2020-02-29" is a valid date but "2021-02-29" is not.

A real leap day: should be true

> /^(19|20)[0-9][0-9]-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|30|31)$/.test("2020-02-29")
true

Not a real date: should be false

> /^(19|20)[0-9][0-9]-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|30|31)$/.test("2021-02-29")
true
delixfe commented 3 years ago

This regex is not used for validation. We will remove it from the documentation. Dates and DateTimes must follow ISO 8601.

delixfe commented 3 years ago

@ypiguet-epfl Thanks again for raising the issue. I have updated the documentation.