models: don't attempt to format invalid phone numbers
This is a defensive-programming measure, because formatting an invalid phone number may truncate some leading numbers.
This commit is contained in:
parent
f35d18cd5c
commit
e32c9a9f94
2 changed files with 14 additions and 1 deletions
|
@ -50,6 +50,13 @@ class Champs::PhoneChamp < Champs::TextChamp
|
|||
|
||||
def to_s
|
||||
return '' if value.blank?
|
||||
Phonelib.parse_for_countries(value, DEFAULT_COUNTRY_CODES).full_national
|
||||
|
||||
if Phonelib.valid_for_countries?(value, DEFAULT_COUNTRY_CODES)
|
||||
Phonelib.parse_for_countries(value, DEFAULT_COUNTRY_CODES).full_national
|
||||
else
|
||||
# When he phone number is possible for the default countries, but not strictly valid,
|
||||
# `full_national` could mess up the formatting. In this case just return the original.
|
||||
value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue