Sha256: 0643c2aae530dea785317e55f483942715a72c80545fc2e90a2c2009087b968f

Contents?: true

Size: 260 Bytes

Versions: 3

Compression:

Stored size: 260 Bytes

Contents

class PhoneValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    return if value.blank?
    unless value.to_s.gsub(/[\s-]+/, '').length >= 10
      record.errors.add attribute, :must_have_at_least_10_digits
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
activemodel-validators-2.0.0 lib/activemodel-validators/phone_validator.rb
activemodel-validators-1.2.0 lib/activemodel-validators/phone_validator.rb
activemodel-validators-1.1.0 lib/activemodel-validators/phone_validator.rb