是否有宝石可以正常化和格式化红宝石中的美国电话号码? [英] Is there a gem that normalizes and format US phone numbers in ruby?
问题描述
我正在使用phony格式化电话号码(这意味着,如果我输入xxx-xxx-xxxx,它会转换为字符串,并在删除前先告诉是否有(1)).
I was using phony to format phone numbers (meaning, if I put in xxx-xxx-xxxx it would convert to a string, and also tell if there is a (1) before to remove it).
但这确实不适用于我们的电话号码,而是为国际号码设计的.
But it really doesn't work for us phone number, it's designed for international numbers.
有一个等价物吗?
谢谢.
http://rubygems.org/gems/phony
推荐答案
今年早些时候,我回顾了一堆用于解析和格式化电话号码的红宝石宝石.它们分为多个组(请参见下文). TLDR:我用的是电话".它可能对您有用,因为您可以指定电话号码中不包含国家/地区代码的默认国家/地区代码.
Earlier this year, I reviewed a bunch of ruby gems that parse and format phone numbers. They fall into a number of groups (see below). TLDR: I used 'phone'. It might work for you because you can specify a default country code that it uses if your phone number doesn't include one.
1)以美国为中心:
大语音(0.1.4)
phone_wrangler(0.1.3)
simple_phone_number(0.1.9)
big-phoney (0.1.4)
phone_wrangler (0.1.3)
simple_phone_number (0.1.9)
2)取决于rails或active_record:
电话号码(1.2.0)
validates_and_formats_phones(0.0.7)
phone_number (1.2.0)
validates_and_formats_phones (0.0.7)
3)已合并回到后备箱中的电话"叉:
elskwid电话(0.9.9.4)
tfe-phone(0.9.9.1)
elskwid-phone (0.9.9.4)
tfe-phone (0.9.9.1)
4)依靠您提前知道该地区
音素(0.1.0)
5)几乎对我有用
电话(0.9.9.3)
phone (0.9.9.3)
6)在宝石名称中不包含子字符串"phone" (我看到您尝试过此操作)
6) does not contain the substring 'phone' in the gem name (edit: I see you tried this one)
phony(1.6.1)
phony (1.6.1)
这些分组可能有点不公平或已过时,请随时发表评论.我必须承认,当时有多少人部分地重新发明了这种特殊的车轮,我对此感到有些沮丧.
These groupings may be somewhat unfair or out of date so feel free to comment. I must admit I was a little frustrated at the time at how many people had partially re-invented this particular wheel.
这篇关于是否有宝石可以正常化和格式化红宝石中的美国电话号码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!