Sha256: f08f778b28991552a1802c6ba39193f853c4a2322270ad71ec3dc14fea8bd73a

Contents?: true

Size: 561 Bytes

Versions: 1

Compression:

Stored size: 561 Bytes

Contents

require 'active_model'

module ValidatesPhoneFormatOf
  Regexp = /\A\+?[1-9]\d{1,14}\z/
end

module ActiveModel
  module Validations
    class PhoneFormatValidator < EachValidator
      def validate_each(record, attribute, value)
        record.errors.add(attribute, :invalid_phone, options.merge({:value => value})) if value.to_s !~ ValidatesPhoneFormatOf::Regexp
      end
    end

    module HelperMethods
      def validates_phone_format_of(*attr_names)
        validates_with PhoneFormatValidator, _merge_attributes(attr_names)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
validates_phone_format_of-2.0.0 lib/validates_phone_format_of.rb