Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to validate that a number is not toll free?

I'm trying to validate that a number is not toll free but not sure how to set this up via the baked in validation helpers.

Here's what I have done so far:

validates :local_phone, :format => { :with => /^(\+?1)?(8(00|55|66|77|88)[2-9]\d{6})$/, :message => "cannot be a toll-free number" }

However, it validates that the number is toll free. I've tried to switch it via ! but to no avail. Before writing my own validates_with class I thought it may be best to ask around.

like image 565
Northband Avatar asked Nov 21 '25 12:11

Northband


1 Answers

How to validate that a number is not toll free? Just call that number and find out :-)

He got the answer already (refer the above comment). I'm just reposting it again so that this question won't appear in "Unanswered" section.

validates :local_phone, :format => { 
   :with => /^(?!(+?1)?(8(00|55|66|77|88)[2-9]\d{6})).{10}$/, 
   :message => "cannot be a toll-free number" }
like image 199
devsathish Avatar answered Nov 24 '25 05:11

devsathish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!