daddyz / phonelib

Ruby gem for phone validation and formatting using google libphonenumber library data
MIT License
1.04k stars 130 forks source link

Valid US phone number being reported as invalid #247

Open yogesh-stripe opened 2 years ago

yogesh-stripe commented 2 years ago

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

jg-stripe commented 2 years ago

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

wflanagan commented 2 years ago

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.

tanelsuurhans commented 2 years ago

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

epidevops commented 2 years ago

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

usama520 commented 2 years ago

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

daddyz commented 2 years ago

@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
tisdall commented 3 months ago

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)