0

I am using the libphonenumber library for node.js

In the google demo for this library, if I enter an invalid phone number, the intl format is not populated. But when I try to parse an invalid number via node.js library, it creates the intl string representation irrespective of whether the number is valid or not.

I need to make sure that only valid numbers are converted and invalids to return null.

As an example, consider this:

var phoneProto = phoneUtil.parse("12213", "IN");
phoneProto.intl = phoneUtil.format(phoneProto, 1);
sails.log.debug(phoneProto.intl);

Output

+91 12213

How can I make sure only valid ones are returned ?

Mandeep Singh
  • 7,674
  • 19
  • 62
  • 104

1 Answers1

1

According to the library's documentation,

parse(java.lang.String numberToParse, java.lang.String defaultRegion)

Parses a string and returns it in proto buffer format. This method will throw a NumberParseException if the number is not considered to be a possible number. Note that validation of whether the number is actually a valid number for a particular region is not performed. This can be done separately with isValidNumber(PhoneNumber).

pratZ
  • 3,078
  • 2
  • 20
  • 29