我有一个将电话号码存储为 '+11231231234'
的应用程序。为了方便用户,我在 View 中将其转换为:+1(123) 123-1234
。我在 Rails 中使用 number_to_phone
助手来完成它:
<%= number_to_phone(call.From, :area_code => true) %>
我还想从 View 中删除 +1
。如果前两个字符是 +1
,我需要写什么来删除电话号码的前两个字符?
最佳答案
number_to_phone(call.From, :area_code => true).gsub(/^\+\d/, '')
关于ruby-on-rails - Rails number_to_phone : Remove country code from phone number,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13018512/