Class: PhonyNumberValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/validators/phony_number_validator.rb

Overview

Uses the Phony.plausible method to validate an attribute. Usage:

validate :phone_number, :phony_number => true

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object

Validates a String using Phony.plausible? method.



7
8
9
10
# File 'lib/validators/phony_number_validator.rb', line 7

def validate_each(record, attribute, value)
  return if value.blank?
  record.errors[attribute] << (options[:message] || "is an invalid number") if not Phony.plausible?(value)
end