Andrea Bazán
Andrea Bazán

Reputation: 83

ACTIVE RECORD REGULAR EXPRESSION

I need to know how use regular expression with active record. I need to create a custom validation where the phone can not have less than 10 digits without counting non-numeric characters. Thank you so much for your help!.

Upvotes: 1

Views: 130

Answers (1)

Sebastián Palma
Sebastián Palma

Reputation: 33420

You can validate the phone format in your model, and in the with option to pass the regex:

validates :phone, format: { with: /\d{10,}/ }

In this case the phone must have ten or more digits. Note are ten digits one after another.

Upvotes: 3

Related Questions