Validating phone number in ruby

前端 未结 6 790
渐次进展
渐次进展 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条回答
  •  猫巷女王i
    2021-01-18 10:12

    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
    

提交回复
热议问题