Class: PhoneValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/kangal/phone.rb

Overview

All phones number should be store e.164 format standard

Instance Method Summary collapse

Instance Method Details

#validate_each(object, attribute, value) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/kangal/phone.rb', line 6

def validate_each(object, attribute, value)

  return if options[:allow_nil] && value.nil?
  return if options[:allow_blank] && value.blank?

  if options[:tr]
    object.errors[attribute] << I18n.t('kangal.validations.common.invalid') unless value =~ /^(90)+\d{10}$/i
  end

  object.errors[attribute] << I18n.t('kangal.validations.phone.tr') unless value =~ /^\d{11,14}$/i
end