Проверка номера телефона в рубине

Каковы правила проверки номера телефона в Северной Америке? Кроме того, есть лиregex Я могу использовать? Есть ли драгоценный камень, чтобы сделать это?

Вот несколько правил, которые я имею в виду

A 10 digit number no special characters A positive number

Ответы на вопрос(6)

class Phne
def ad
puts "Enter your phone number"
re=gets.chomp
if re= ~/\b^([0-9]{10})$\b/
puts "Valid phone number"
else
puts "Invalid phone number"
end
end
end

obj=Phne.new
obj.ad

Error: User Rate Limit ExceededError: User Rate Limit Exceeded:

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

  • Error: User Rate Limit Exceeded

    Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

    Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

    The number 10 digits long.  We'll call this pattern:
        ABC DEF XXXX
    
    A may not be 0 or 1.
    
    B may not be 9.
    
    A+B may not be 37 or 96.
    
    B+C may not be 11.
    
    D may not be 0 or 1.
    

    Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit Exceeded

    Решение Вопроса

    Error: User Rate Limit Exceeded

    Error: User Rate Limit ExceededError: User Rate Limit Exceeded

    Error: User Rate Limit ExceededError: User Rate Limit Exceeded

    Error: User Rate Limit Exceeded

    Error: User Rate Limit ExceededError: User Rate Limit Exceeded

    Try this

    (?:\+?|\b)[0-9]{10}\b
    

    Explanation

    @"
    (?:         # Match the regular expression below
                   # Match either the regular expression below (attempting the next alternative only if this one fails)
          \+          # Match the character “+” literally
             ?           # Between zero and one times, as many times as possible, giving back as needed (greedy)
       |           # Or match regular expression number 2 below (the entire group fails if this one fails to match)
          \b          # Assert position at a word boundary
    )
    [0-9]       # Match a single character in the range between “0” and “9”
       {10}        # Exactly 10 times
    \b          # Assert position at a word boundary
    "
    

    Ваш ответ на вопрос