I am new to Ruby on Rails, looking for any suggestions to validate a phone number to be xxx-xxx-xxxx. Appreciate any suggestions. My phone_number column type is a string. Thanks!
Asked
Active
Viewed 2.0k times
3
-
2Is it this hard to search in google? http://stackoverflow.com/questions/123559/a-comprehensive-regex-for-phone-number-validation – BvuRVKyUVlViVIc7 Sep 18 '13 at 18:20
1 Answers
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" }

ExWei
- 350
- 3
- 8
-
That is a good way of doing it, but what if i want to do it in the html page itself, like the email_field number_field etc? – Alfie Jul 03 '15 at 04:58
-
-