-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export the list of supported countries for isPostalCode, locales for isMobilePhone, etc... #815
Comments
I am facing the same issue. I have a list of supported countries which are not all supported by |
I'd be happy to accept a PR that exports the list. |
@profnandaa I don't think the list of mobile phone locales is being exported currently. |
@chriso -- ooh, got it. Let me be on it. |
This commit exports supported locales for the following functions: - isAlpha -> isAlphaLocales - isAlphanumeric -> isAlphanumericLocales - isMobilePhone -> isMobilePhoneLocales fixes validatorjs#815
This commit exports supported locales for the following functions: - isAlpha -> isAlphaLocales - isAlphanumeric -> isAlphanumericLocales - isMobilePhone -> isMobilePhoneLocales fixes validatorjs#815
This commit exports the list of supported locales for `isFloat` as `isFloatLocales` Ref: validatorjs#815, validatorjs#891, follow up for validatorjs#890
I would like to use
isPostalCode
for form validation in a situation where the country code may be input by the user. I want to validate all the common countries (Canada, US, UK, etc...) that validator supports but if validator doesn't know how to validate a country's postal code I just want to consider all input valid.The problem is that
isPostalCode
will throw a generic Error instance if the country code is one it does not understand. Which I cannot differentiate from a programming error without checking against themessage
(bad practice). The only thing I can do at the moment is hardcode a list of what countries are supported byisPostalCode
in my code and check against that list before calling it to determine if it's safe to call. However this leaves open the possibility that validator will add support for another country's postal codes (I even found a database that seems to have more than what is in validator that validator might want to source some info from), which will make my list be out of date.It would be nice if the list of countries supported by
isPostalCode
would be exported somewhere so I could import it and check my user inputted country codes so see if the postal code is safe to validate.It would also work to add an option to consider postal codes from all unknown countries as valid. However I am also considering the possibility of doing something like
required={isRequired && canValidatePostalCodeForCountry(countryCode)}
to disable postal codes being required in forms when it's not known if the country has them.The text was updated successfully, but these errors were encountered: