libPhoneNumber-iOS icon indicating copy to clipboard operation
libPhoneNumber-iOS copied to clipboard

Checking for US number like 14155552671 isValidNumber returned is false

Open amitkumarsharma008 opened this issue 8 years ago • 6 comments

Tested on the link for this number(14155552671), both isValid and isPossible number returns true. But the ios library for isValidNumber returns false.

amitkumarsharma008 avatar Feb 25 '17 08:02 amitkumarsharma008

I can confirm this - for US numbers, libPhoneNumber-iOS says they are invalid although the number is valid according to the linked website. I tried with +115417543010.

thailow avatar Mar 04 '17 21:03 thailow

OK I will check it.

iziz avatar Mar 07 '17 02:03 iziz

With https://github.com/iziz/libPhoneNumber-iOS/pull/175, the following code appears to work:

NSError *error = nil; NBPhoneNumber *phoneNumberUS = [phoneUtil parse:@"14155552671" defaultRegion:@"US" error:&error]; NSLog(@"- isValidNumber [%@]", [phoneUtil isValidNumber:phoneNumberUS] ? @"YES" : @"NO"); NSLog(@"- isPossibleNumber [%@]", [phoneUtil isPossibleNumber:phoneNumberUS error:&error] ? @"YES" : @"NO"); NSLog(@"- getRegionCodeForNumber [%@]", [phoneUtil getRegionCodeForNumber:phoneNumberUS]);

2017-03-19 21:32:32.644 MetadataGenerator[25153:3448544] - isValidNumber [YES] 2017-03-19 21:32:34.856 MetadataGenerator[25153:3448544] - isPossibleNumber [YES] 2017-03-19 21:32:36.578 MetadataGenerator[25153:3448544] - getRegionCodeForNumber [US]

dmaclach avatar Mar 20 '17 04:03 dmaclach

Thanks a lot guys, everything running smoothly now!

thailow avatar Mar 29 '17 20:03 thailow

@thailow what did you end up doing to solve this? We are running into the same issue now.

cameronehrlich avatar May 07 '20 18:05 cameronehrlich

Turns out Puerto Rico's area code (787) is not a valid prefix for the US region...

cameronehrlich avatar May 07 '20 20:05 cameronehrlich