phonelib
phonelib copied to clipboard
Valid US phone number being reported as invalid
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
Note: This is a relatively new area code: https://www.fox4news.com/news/new-area-code-945-approved-for-dallas-area
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.
This has now been open for a while - any movement on these simple additions?
This also seem so be an issue when Faker is used and numbers begin with 555
Any workaround regarding this issue? I am having the same issue with "787" area code.
@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
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)