Class: ActiveModel::Validations::PhoneValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/active_validators/active_model/validations/phone_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



6
7
8
9
# File 'lib/active_validators/active_model/validations/phone_validator.rb', line 6

def validate_each(record, attribute, value)
  country_code = Country.new(options[:country].to_s.upcase).country_code unless options[:country].blank?
  record.errors.add(attribute, options[:message]) if value.blank? || ! (options[:country].blank? ? Phony.plausible?(value) : Phony.plausible?(value, :cc => country_code) )
end