phonelib icon indicating copy to clipboard operation
phonelib copied to clipboard

Valid US phone number being reported as invalid

Open yogesh-stripe opened this issue 3 years ago • 7 comments

I am using phonelib 0.6.46 and I am having trouble validating some US phone numbers with area code 945. Wondering if this is a known bug.

Here is an example failure: irb(main):002:0> Phonelib.parse('+19450000000', 'US').valid_for_country?('US') => false

yogesh-stripe avatar Dec 03 '21 01:12 yogesh-stripe

Note: This is a relatively new area code: https://www.fox4news.com/news/new-area-code-945-approved-for-dallas-area

jg-stripe avatar Dec 03 '21 02:12 jg-stripe

To add to this..

Phonelib.default_country('US')
Phonelib.parse('(604) 526-7275').valid_for_country?('US') # false

604 is NOT a new area code.

I ran across this trying to figure out why this wasn't parsing or formatting correctly. Instead, the parsing thinks this is a +60 country code breaking the () which doesn't make a lot of sense.

wflanagan avatar Jan 09 '22 15:01 wflanagan

This has now been open for a while - any movement on these simple additions?

tanelsuurhans avatar Feb 08 '22 14:02 tanelsuurhans

This also seem so be an issue when Faker is used and numbers begin with 555

epidevops avatar Feb 10 '22 02:02 epidevops

Any workaround regarding this issue? I am having the same issue with "787" area code.

usama520 avatar Feb 10 '22 12:02 usama520

@yogesh-stripe @jg-stripe @tanelsuurhans @usama520 This number is also parsed as invalid in original libphonenumber. You can check it here and open an issue for them. Gem's data is based on it. You can wait for them to fix it or you can use this method (in your app initializer) to add missing validation regex like here:

Phonelib.add_additional_regex :us, Phonelib::Core::FIXED_LINE, '945\d{7}'

I am just not sure regarding numbering plan rules in these areas, but you can make regex to be more strict.

@wflanagan You are not using default_country method correctly. It should be used like:

 Phonelib.default_country = :us

daddyz avatar Feb 23 '22 06:02 daddyz

Not sure if this helps but I think '+19450000000' is seen as invalid due to the '0000000'.

irb(main):010:0> Phonelib.parse('+19450000000', 'US').valid_for_country?('US')
=> false
irb(main):012:0> Phonelib.parse('+19452000000', 'US').valid_for_country?('US')
=> true

The first digit of the local part can only be 2-9 (from when you could dial locally without the area code... 1 would be long distance and 0 would be the operator)

tisdall avatar Mar 20 '24 18:03 tisdall