Sha256: 6779b40adb8c29f77d3da616e089542fb3d99cd7389c051625312913fe0477c0

Contents?: true

Size: 350 Bytes

Versions: 13

Compression:

Stored size: 350 Bytes

Contents

class CreditCardFormatValidator < ActiveModel::EachValidator
  def validate_each(object, attribute, value)
    unless value =~ /((4\d{3})|(5[1-5]\d{2})|(6011)|(34\d{1})|(37\d{1}))-?\d{4}-?\d{4}-?\d{4}|3[4,7][\d\s-]{15}/
      object.errors[attribute] << (options[:message] || "enter a valid credit card number (Visa or Mastercard)")
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ama_validators-0.0.13 lib/ama_validators/credit_card_format_validator.rb
ama_validators-0.0.12 lib/ama_validators/credit_card_format_validator.rb
ama_validators-0.0.11 lib/ama_validators/credit_card_format_validator.rb
ama_validators-0.0.10 lib/ama_validators/credit_card_format_validator.rb
ama_validators-0.0.9 lib/ama_validators/credit_card_format_validator.rb
ama_validators-0.0.8 lib/ama_validators/credit_card_format_validator.rb
ama_validators-0.0.7 lib/ama_validators/credit_card_format_validator.rb
ama_validators-0.0.6 lib/ama_validators/credit_card_format_validator.rb
ama_validators-0.0.5 lib/ama_validators/credit_card_format_validator.rb
ama_validators-0.0.4 lib/ama_validators/credit_card_format_validator.rb
ama_validators-0.0.3 lib/ama_validators/credit_card_format_validator.rb
ama_validators-0.0.2 lib/ama_validators/credit_card_format_validator.rb
ama_validators-0.0.1 lib/ama_validators/credit_card_format_validator.rb