Validating phone number in ruby

前端 未结 6 724
渐次进展
渐次进展 2021-01-18 09:37

What are the rules for validating a North American phone number? Also, is there a regex I can use? Is there a gem to do this?

Here are few rules I have

6条回答
  •  礼貌的吻别
    2021-01-18 09:59

    If you want something more advanced than a regex, Twilio has an API that can do this:

    Twilio Lookup is a REST API that can:

  • Verify that a phone number exists
  • Format any international phone number into its local standard
  • Determine if a phone number is a cell phone, VOIP or landline
  • Discover information about a phone number’s carrier

  • I haven't used this yet! But it should work, though you do need a (free) Twilio account. (Also I'm not affiliated with Twilio, other than having a free account I'm playing with.)

提交回复
热议问题