gpt4 book ai didi

ruby-on-rails - Rails number_to_phone : Remove country code from phone number

转载 作者:数据小太阳 更新时间:2023-10-29 08:16:34 25 4
gpt4 key购买 nike

我有一个将电话号码存储为 '+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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com