Skip to content

question: IsPhoneNumber region is being used as country, is that ok? #2637

@matgott

Description

@matgott

I'm using IsPhoneNumber('US') to validate US numbers but for example a Puerto Rico phone number is returning false.

The problem:

Looking at isPhoneNumber decorator source code I saw this:

var phoneNumber = parsePhoneNumber(value, region);
/**
 * We fail the validation if the user provided a region code
 * and it doesn't match with the country code of the parsed number.
 **/
if (region && phoneNumber.country !== region) {
    return false;
}

So... basically a phone number from Puerto Rico is from the country PR but the region is US. The decorator is returning false is this the expected behavior?

For example this is the result from parsePhoneNumber for a Puerto Rico phone number:

{
  country: 'PR',
  countryCallingCode: '1',
  nationalNumber: '7876xxxxxx',
  number: '+17876xxxxxx',
  getMetadata: [Function (anonymous)],
  __countryCallingCodeSource: undefined
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questionQuestions about the usage of the library.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions