typestack / class-validator

Decorator-based property validation for classes.
MIT License
10.89k stars 786 forks source link

feat: change libphonenumber-js to use the max metadata set #731

Open rbiggers opened 4 years ago

rbiggers commented 4 years ago

I am trying to validate phone numbers against country codes but it seems class validator is importing the min version of libphonenumber-js. The IsPhoneNumber returns inconsistent validation results.

While using the min version of libphonenumber-js I validate '+91 1234-123456' against country code 'US' the result is true which is not expected.

While using the max version of libphonenumber-js/max I validate '+91 1234-123456' against country code 'US' the result is false which is expected.

A quote from their docs: "Importing functions directly from libphonenumber-js results in using the min metadata which means loose (non-strict) phone number validation via .isValid() and no getting phone number type via .getType() for most countries."

min-vs-max-vs-mobile-vs-core

So to circle back should class validator be using libphonenumber-js/max instead of libphonenumber-js in the import?

I have included a screenshot fo the code below linked here

image

vlapo commented 3 years ago

@NoNameProvided could you please check this one? min version = 80 kilobytes and max version = 145 kilobytes. Maybe we should use more precise max version (60 kilobytes is not so big deal)

NoNameProvided commented 3 years ago

We can add it, but then the other end of the users will come who will say 60 kilobytes is a big deal (which can be a case for websites). Anyway let's go with adding it and then if someone complains we will discuss it in detail.