Puerto Rican phone number parsing/validation issues
Opened this issue · 1 comments
james-caresnap commented
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 commented
Looks like some adjacent stuff going on in this commit. I tried my test case against master
, but same result for validation.