3

我是 Ruby on Rails 的新手,正在寻找任何建议来验证电话号码是否为 xxx-xxx-xxxx。感谢任何建议。我的 phone_number 列类型是字符串。谢谢!

4

1 回答 1

6

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" }
于 2013-09-18T19:13:00.903 回答