phony icon indicating copy to clipboard operation
phony copied to clipboard

Decide on whether Phony handles the +

Open floere opened this issue 6 years ago • 2 comments

Should Phony also handle the + (country calling code indicator) when passed to e.g. split?

floere avatar Apr 22 '19 19:04 floere

I'd say yes! For instance, currently I use phony_normalize from phony-rails, which saves a number with a + in DB.

But then, when I try to format it in national format, if I leave the +, I get a Phony::FormattingError: Phony could not format the given number. Is it a phone number? error. So I need to remove the + before passing it to #format.

Could #format just handle the + for me?

capripot avatar Jun 11 '23 01:06 capripot

@capripot Thanks for your input, I appreciate it! 😊 I think the core issue here is that it makes little sense to also store a + in the database, if you only store full E164 conforming numbers (not sure I agree with phony-rails' decision here to leave the + in – but I am missing context, I assume). format is designed to work only on E164 numbers, ie. only the digits. Feel free to call normalize beforehand and call format on the result. Does that help?

floere avatar Jun 11 '23 12:06 floere