Skip to content

[Refactor proposal] Use countrycode instead of locale for some validators #2171

@WikiRik

Description

@WikiRik

I will update this later with a proper table, but some validators like isMobilePhone and isLicensePlate do not need a specified locale since the values are not dependent on the language used but only the country. For others, like isAlpha, we should remain using the locales. In any case country codes and locales should not be mixed (like in isIdentityCard)

What I have in mind is that we allow the countrycodes to be used first and that those are mapped to the current locales so both are supported but it's easy to remove the locales in a later major version. (I will provide an example in the updated issue)

My idea is that this is done after #1874 has been finished and we have split the test cases in different files. That makes it easier to see which tests are for the new syntax and which ones of the legacy syntax (see https://github.com/validatorjs/validator.js/blob/master/test/validators/isAfter.test.js for example). I would not recommend to do this in combination with other refactors (like #2124 ) so the scope of the refactors remain clear.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions