Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails number_to_phone: Remove country code from phone number

I have an application that stores phone numbers as '+11231231234'. To make it easier for the user, I convert it to: +1(123) 123-1234 in the view. I use the number_to_phone helper in rails to do it:

<%= number_to_phone(call.From, :area_code => true) %>

I also want to remove the +1 from the view. What would I need to write to remove the first two characters of the phone number if the first two characters are +1?

like image 555
Stepan Parunashvili Avatar asked Dec 10 '25 15:12

Stepan Parunashvili


1 Answers

number_to_phone(call.From, :area_code => true).gsub(/^\+\d/, '')
like image 184
Kyle Avatar answered Dec 12 '25 11:12

Kyle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!