# Validating phone number with country code for (Twilio)

**URL:** <https://www.ruby-forum.com/t/validating-phone-number-with-country-code-for-twilio/259430>\
**Category:** Uncategorized\
**Created:** [May 1, 2020, 2:57pm UTC](https://www.ruby-forum.com/t/validating-phone-number-with-country-code-for-twilio/259430 "2020-05-01T14:57:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcoder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a3d4f5/32.png) [@dcoder](https://www.ruby-forum.com/u/dcoder)\
**Post date:** [May 1, 2020, 2:57pm UTC](https://www.ruby-forum.com/t/validating-phone-number-with-country-code-for-twilio/259430/1 "2020-05-01T14:57:33Z")

</div>

Greetings, I am trying to build a regex that checks whether or not a phone number is formatted correctly for Twilio.

validates\_format\_of :phone\_number, :with =\> …  
If the format is incorrect, Twilio is unable to send back the api response to the correct conversation record. Does anyone know how to build a regex that follows this format +11235666666?

---

<div class="post-metadata">

**Author:** ![pcl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ecae2f/32.png) [@pcl](https://www.ruby-forum.com/u/pcl)\
**Post date:** [May 1, 2020, 6:21pm UTC](https://www.ruby-forum.com/t/validating-phone-number-with-country-code-for-twilio/259430/2 "2020-05-01T18:21:19Z")

</div>

What is the format? + followed by 11 digits?

```auto
2.7.1 :001 > re = /\+\d\d\d\d\d\d\d\d\d\d\d/
2.7.1 :002 > "+11235666666" =~ re
 => 0 
2.7.1 :003 > "11235666666" =~ re
 => nil 
2.7.1 :004 > "11235666" =~ re
 => nil 
2.7.1 :005 > "+11235666" =~ re
 => nil 

```

If you have other constraints, replace the relevant \d with the required value/range.

---

<div class="post-metadata">

**Author:** ![dcoder](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a3d4f5/32.png) [@dcoder](https://www.ruby-forum.com/u/dcoder)\
**Post date:** [May 1, 2020, 7:41pm UTC](https://www.ruby-forum.com/t/validating-phone-number-with-country-code-for-twilio/259430/3 "2020-05-01T19:41:47Z")

</div>

Very nice. Thank you.
