fix: `@IsPhoneNumber` decorator does not match E.164 format
See original GitHub issueDescription
Hi, I use the class-validator library to validate request data on a Node.js app. I have problems with validating phone numbers with intl. prefix (use ‘ZZ’ as a region)!
Example
class PhoneNumberWithIssue {
@IsNotEmpty({ message: 'ERROR_EMPTY_PHONE_NUMBER_FIELD' })
@IsPhoneNumber('ZZ', { message: 'ERROR_INVALID_PHONE_NUMBER' })
phoneNumber!: string;
}
const invalidPhoneNumber = new PhoneNumberWithIssue();
invalidPhoneNumber.phoneNumber = "+380981111111++++++++++=====++++=+";
validate(invalidPhoneNumber).then(errors => {
if (errors.length > 0) {
console.log("validation failed. errors: ", errors);
} else {
console.log("validation succeed"); // Validation is succeeded, but the phone number is not valid!
}
});
Dependencies
"class-validator": "^0.10.0"
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:10 (9 by maintainers)
Top Results From Across the Web
IsPhoneNumber() npm class validator how to add multiple ...
So solution is: parse phone number; if it's valid check country code; if it's valid pass to next built-in decorator. So I've created ......
Read more >Javascript E164 Phone Number Validation - Kevin Chisholm
I this article you will learn how to set up a JavaScript E164 phone number validation system for your forms. E.164 is the...
Read more >Phone numbers in JavaScript using E.164, libphonenumber ...
The E.164 standard might be great for storage, but terrible for two things. First, virtually no one would type or read out their...
Read more >Computer Programming using Python
Python variables do not need explicit declaration to reserve memory space. ... If values of two operands are not equal, then condition becomes...
Read more >libphonenumber-js - npm
Since libphonenumber-js is not a dialing library (we're not Android phone operaing ... number: string — The phone number in E.164 format.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For anyone reading this like I am and wondering why this hasn’t been fixed, here is a quick workaround: is-e164-phone-number.decorator.ts
Usage:
The related PR has been closed as out-of-date because the libary used to parse phone numbers has changed. This issue needs to be re-tested with the new lib.