Sha256: ec1a295ae4bb2a6165c89b2caab7f46e3d864ab815567b67325e4f1161ea963e

Contents?: true

Size: 510 Bytes

Versions: 1

Compression:

Stored size: 510 Bytes

Contents

require 'active_model'

module ValidatesPhoneFormatOf
end

module ActiveModel
  module Validations
    class PhoneFormatValidator < EachValidator
      def validate_each(record, attribute, value)
        record.errors.add(attribute, :invalid, options.merge({value: value})) if value.to_s !~ /\A\+?[1-9]\d{1,14}\z/
      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-1.0.1 lib/validates_phone_format_of.rb