Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Puerto Rican phone number parsing/validation issues #262

Open
james-caresnap opened this issue Jul 25, 2022 · 1 comment
Open

Puerto Rican phone number parsing/validation issues #262

james-caresnap opened this issue Jul 25, 2022 · 1 comment

Comments

@james-caresnap
Copy link

james-caresnap commented Jul 25, 2022

Phonelib version: 0.7.0
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]

I'm not really sure if this is a bug, but it's strange behavior and diverges from libphonenumber's behavior. For the phone number (787) 240-2750, which is a Puerto Rican phone number, libphonenumber with the default country set to US parses like this:

****Parsing Result:****
{"country_code":1,"national_number":7872402750,"raw_input":"(787) 240-2750","country_code_source":20}

****Validation Results:****
Result from isPossibleNumber(): true
Result from isValidNumber(): true
Result from isValidNumberForRegion(): false
Phone Number region: PR
Result from getNumberType(): FIXED_LINE_OR_MOBILE

phonelib, however does not give the same validation results,:

irb> Phonelib.default_country = :us
irb> phone = Phonelib.parse("(787) 240-2750")
irb> phone.possible?
true
irb> phone.valid?
false
irb> phone.valid_for_country?(:us)
false

However, it behaves the same as libphonenumber if you reformat in e164 or prefix with the 1 international calling code:

irb> Phonelib.valid?(Phonelib.parse("(787) 240-2750").e164)
true
irb> Phonelib.valid?("1 (787) 240-2750")
true

May be related to issue #220.

@james-caresnap
Copy link
Author

Looks like some adjacent stuff going on in this commit. I tried my test case against master, but same result for validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant