Sha256: 95557e0f8ac59b9c43acb07278fa8f83e677fc5753f4039a2432670763e975dc

Contents?: true

Size: 329 Bytes

Versions: 10

Compression:

Stored size: 329 Bytes

Contents

class PhoneNumberFormatValidator < ActiveModel::EachValidator
  def validate_each(object, attribute, value)
    unless value =~ /\A(\+?1( |-)?)?(\(?[0-9]{3}\)?|[0-9]{3})( |-)?([0-9]{3}( |-)?[0-9]{4})\z/
      object.errors[attribute] << (options[:message] || "enter a valid 10-digit number (e.g. 587-555-5555)")
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ama_validators-0.0.13 lib/ama_validators/phone_number_format_validator.rb
ama_validators-0.0.12 lib/ama_validators/phone_number_format_validator.rb
ama_validators-0.0.11 lib/ama_validators/phone_number_format_validator.rb
ama_validators-0.0.10 lib/ama_validators/phone_number_format_validator.rb
ama_validators-0.0.9 lib/ama_validators/phone_number_format_validator.rb
ama_validators-0.0.8 lib/ama_validators/phone_number_format_validator.rb
ama_validators-0.0.7 lib/ama_validators/phone_number_format_validator.rb
ama_validators-0.0.6 lib/ama_validators/phone_number_format_validator.rb
ama_validators-0.0.5 lib/ama_validators/phone_number_format_validator.rb
ama_validators-0.0.4 lib/ama_validators/phone_number_format_validator.rb