Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 Ruby on Rails 的新手,正在寻找任何建议来验证电话号码是否为 xxx-xxx-xxxx。感谢任何建议。我的 phone_number 列类型是字符串。谢谢!
If you need it to validate phone field in model, you can use this code:
validates :phone_number, format: { with: /\d{3}-\d{3}-\d{4}/, message: "bad format" }