class TaiwanValidator::PhoneNumberValidator

Public Class Methods

valid?(phone_number) click to toggle source
# File lib/taiwan_validator/phone_number_validator.rb, line 3
def valid?(phone_number)
  phone_number.gsub(/[\+\-\s]/, "") =~ /\A(886|0)[2-9]([0-9]{6,8})\z/
end

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# File lib/taiwan_validator/phone_number_validator.rb, line 8
def validate_each(record, attribute, value)
  unless self.class.valid?(value)
    record.errors.add(attribute, options[:message] || :invalid)
  end
end