flash_validators 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -3
  3. data/README.md +483 -232
  4. data/config/locales/en.yml +12 -0
  5. data/lib/flash_validators.rb +6 -0
  6. data/lib/flash_validators/matchers/ensure_valid_alpha_format_of.rb +18 -0
  7. data/lib/flash_validators/matchers/ensure_valid_alpha_numeric_format_of.rb +18 -0
  8. data/lib/flash_validators/matchers/ensure_valid_boolean_format_of.rb +2 -4
  9. data/lib/flash_validators/matchers/ensure_valid_credit_card_format_of.rb +18 -0
  10. data/lib/flash_validators/matchers/ensure_valid_currency_format_of.rb +2 -4
  11. data/lib/flash_validators/matchers/ensure_valid_email_format_of.rb +2 -4
  12. data/lib/flash_validators/matchers/ensure_valid_equality_matcher_of.rb +2 -4
  13. data/lib/flash_validators/matchers/ensure_valid_hex_format_of.rb +2 -4
  14. data/lib/flash_validators/matchers/ensure_valid_imei_format_of.rb +2 -4
  15. data/lib/flash_validators/matchers/ensure_valid_ip_format_of.rb +2 -4
  16. data/lib/flash_validators/matchers/ensure_valid_latitude_format_of.rb +2 -4
  17. data/lib/flash_validators/matchers/ensure_valid_longitude_format_of.rb +2 -4
  18. data/lib/flash_validators/matchers/ensure_valid_mac_address_format_of.rb +2 -4
  19. data/lib/flash_validators/matchers/ensure_valid_name_format_of.rb +2 -4
  20. data/lib/flash_validators/matchers/ensure_valid_password_format_of.rb +2 -4
  21. data/lib/flash_validators/matchers/ensure_valid_phone_format_of.rb +2 -4
  22. data/lib/flash_validators/matchers/ensure_valid_slug_format_of.rb +2 -4
  23. data/lib/flash_validators/matchers/ensure_valid_ssn_format_of.rb +2 -4
  24. data/lib/flash_validators/matchers/ensure_valid_url_format_of.rb +2 -4
  25. data/lib/flash_validators/matchers/ensure_valid_username_format_of.rb +2 -4
  26. data/lib/flash_validators/validators/alpha_numeric_validator.rb +17 -0
  27. data/lib/flash_validators/validators/alpha_validator.rb +19 -0
  28. data/lib/flash_validators/validators/credit_card_validator.rb +25 -0
  29. data/lib/flash_validators/validators/password_validator.rb +9 -1
  30. data/lib/flash_validators/version.rb +2 -2
  31. data/spec/lib/alpha_numeric_validator_spec.rb +61 -0
  32. data/spec/lib/alpha_validator_spec.rb +120 -0
  33. data/spec/lib/credit_card_validator_spec.rb +316 -0
  34. data/spec/lib/currency_validator_spec.rb +1 -1
  35. data/spec/lib/password_validator_spec.rb +42 -0
  36. metadata +15 -3
@@ -1,7 +1,10 @@
1
1
  en:
2
2
  errors:
3
3
  messages:
4
+ alpha: "is not a valid alpha characters"
5
+ alpha_numeric: "is not a valid alpha-numeric characters"
4
6
  boolean: "is not a valid boolean"
7
+ credit_card: "is not a valid credit card"
5
8
  currency: "is not a valid currency"
6
9
  email: "is not a valid email"
7
10
  equality: "is not %{operator} %{attr}"
@@ -20,9 +23,18 @@ en:
20
23
  username: "is not a valid username"
21
24
  flash_validators:
22
25
  matchers:
26
+ ensure_valid_alpha_format_of:
27
+ failure_message_for_should: "#{model} should ensure valid alpha format of attribute #{attr}"
28
+ failure_message_for_should_not: "#{model} should not ensure valid alpha format of attribute #{attr}"
29
+ ensure_valid_alpha_numeric_format_of:
30
+ failure_message_for_should: "#{model} should ensure valid alpha numeric format of attribute #{attr}"
31
+ failure_message_for_should_not: "#{model} should not ensure valid alpha numeric format of attribute #{attr}"
23
32
  ensure_valid_boolean_format_of:
24
33
  failure_message_for_should: "#{model} should ensure valid boolean format of attribute #{attr}"
25
34
  failure_message_for_should_not: "#{model} should not ensure valid boolean format of attribute #{attr}"
35
+ ensure_valid_credit_card_format_of:
36
+ failure_message_for_should: "#{model} should ensure valid credit card format of attribute #{attr}"
37
+ failure_message_for_should_not: "#{model} should not ensure valid credit card format of attribute #{attr}"
26
38
  ensure_valid_currency_format_of:
27
39
  failure_message_for_should: "#{model} should ensure valid currency format of attribute #{attr}"
28
40
  failure_message_for_should_not: "#{model} should not ensure valid currency format of attribute #{attr}"
@@ -2,7 +2,10 @@ require 'active_model'
2
2
  require 'active_support'
3
3
  require 'rspec/matchers'
4
4
  require 'flash_validators/version'
5
+ require 'flash_validators/validators/alpha_validator'
6
+ require 'flash_validators/validators/alpha_numeric_validator'
5
7
  require 'flash_validators/validators/boolean_validator'
8
+ require 'flash_validators/validators/credit_card_validator'
6
9
  require 'flash_validators/validators/currency_validator'
7
10
  require 'flash_validators/validators/email_validator'
8
11
  require 'flash_validators/validators/equality_validator'
@@ -21,7 +24,10 @@ require 'flash_validators/validators/url_validator'
21
24
  require 'flash_validators/validators/username_validator'
22
25
 
23
26
  if defined?(RSpec)
27
+ require 'flash_validators/matchers/ensure_valid_alpha_format_of'
28
+ require 'flash_validators/matchers/ensure_valid_alpha_numeric_format_of'
24
29
  require 'flash_validators/matchers/ensure_valid_boolean_format_of'
30
+ require 'flash_validators/matchers/ensure_valid_credit_card_format_of'
25
31
  require 'flash_validators/matchers/ensure_valid_currency_format_of'
26
32
  require 'flash_validators/matchers/ensure_valid_email_format_of'
27
33
  require 'flash_validators/matchers/ensure_valid_equality_matcher_of'
@@ -0,0 +1,18 @@
1
+ RSpec::Matchers.define :ensure_valid_alpha_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "$1234.56")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('errors.messages.alpha'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t('flash_validators.matchers.ensure_valid_alpha_format_of.failure_message_for_should', model: model.class)
13
+ end
14
+
15
+ failure_message_when_negated do |model|
16
+ I18n.t('flash_validators.matchers.ensure_valid_alpha_format_of.failure_message_for_should_not', model: model.class)
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ RSpec::Matchers.define :ensure_valid_alpha_numeric_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "$1234.56")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('errors.messages.alpha_numeric'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t('flash_validators.matchers.ensure_valid_alpha_numeric_format_of.failure_message_for_should', model: model.class)
13
+ end
14
+
15
+ failure_message_when_negated do |model|
16
+ I18n.t('flash_validators.matchers.ensure_valid_alpha_numeric_format_of.failure_message_for_should_not', model: model.class)
17
+ end
18
+ end
@@ -9,12 +9,10 @@ RSpec::Matchers.define :ensure_valid_boolean_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t 'flash_validators.matchers.ensure_valid_boolean_format_of.failure_message_for_should',
13
- model: model.class
12
+ I18n.t('flash_validators.matchers.ensure_valid_boolean_format_of.failure_message_for_should', model: model.class)
14
13
  end
15
14
 
16
15
  failure_message_when_negated do |model|
17
- I18n.t 'flash_validators.matchers.ensure_valid_boolean_format_of.failure_message_for_should_not',
18
- model: model.class
16
+ I18n.t('flash_validators.matchers.ensure_valid_boolean_format_of.failure_message_for_should_not', model: model.class)
19
17
  end
20
18
  end
@@ -0,0 +1,18 @@
1
+ RSpec::Matchers.define :ensure_valid_credit_card_format_of do |attribute|
2
+ match do |model|
3
+ model.send("#{attribute}=", "9999")
4
+ model.valid?
5
+
6
+ if model.errors.has_key?(attribute)
7
+ model.errors[attribute].include?(I18n.t('errors.messages.credit_card'))
8
+ end
9
+ end
10
+
11
+ failure_message do |model|
12
+ I18n.t('flash_validators.matchers.ensure_valid_credit_card_format_of.failure_message_for_should', model: model.class)
13
+ end
14
+
15
+ failure_message_when_negated do |model|
16
+ I18n.t('flash_validators.matchers.ensure_valid_credit_card_format_of.failure_message_for_should_not', model: model.class)
17
+ end
18
+ end
@@ -9,12 +9,10 @@ RSpec::Matchers.define :ensure_valid_currency_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t 'flash_validators.matchers.ensure_valid_currency_format_of.failure_message_for_should',
13
- model: model.class
12
+ I18n.t('flash_validators.matchers.ensure_valid_currency_format_of.failure_message_for_should', model: model.class)
14
13
  end
15
14
 
16
15
  failure_message_when_negated do |model|
17
- I18n.t 'flash_validators.matchers.ensure_valid_currency_format_of.failure_message_for_should_not',
18
- model: model.class
16
+ I18n.t('flash_validators.matchers.ensure_valid_currency_format_of.failure_message_for_should_not', model: model.class)
19
17
  end
20
18
  end
@@ -9,12 +9,10 @@ RSpec::Matchers.define :ensure_valid_email_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t 'flash_validators.matchers.ensure_valid_email_format_of.failure_message_for_should',
13
- model: model.class
12
+ I18n.t('flash_validators.matchers.ensure_valid_email_format_of.failure_message_for_should', model: model.class)
14
13
  end
15
14
 
16
15
  failure_message_when_negated do |model|
17
- I18n.t 'flash_validators.matchers.ensure_valid_email_format_of.failure_message_for_should_not',
18
- model: model.class
16
+ I18n.t('flash_validators.matchers.ensure_valid_email_format_of.failure_message_for_should_not', model: model.class)
19
17
  end
20
18
  end
@@ -21,12 +21,10 @@ RSpec::Matchers.define :ensure_equality_of do |attribute|
21
21
  end
22
22
 
23
23
  failure_message do |model|
24
- I18n.t 'flash_validators.matchers.ensure_valid_equality_format_of.failure_message_for_should',
25
- model: model.class, attr: attribute.inspect, operator: "operator"
24
+ I18n.t('flash_validators.matchers.ensure_valid_equality_format_of.failure_message_for_should', model: model.class, attr: attribute.inspect, operator: "operator")
26
25
  end
27
26
 
28
27
  failure_message_when_negated do |model|
29
- I18n.t 'flash_validators.matchers.ensure_valid_equality_format_of.failure_message_for_should_not',
30
- model: model.class, attr: attribute.inspect, operator: "operator"
28
+ I18n.t('flash_validators.matchers.ensure_valid_equality_format_of.failure_message_for_should_not', model: model.class, attr: attribute.inspect, operator: "operator")
31
29
  end
32
30
  end
@@ -9,12 +9,10 @@ RSpec::Matchers.define :ensure_valid_hex_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t 'flash_validators.matchers.ensure_valid_hex_format_of.failure_message_for_should',
13
- model: model.class
12
+ I18n.t('flash_validators.matchers.ensure_valid_hex_format_of.failure_message_for_should', model: model.class)
14
13
  end
15
14
 
16
15
  failure_message_when_negated do |model|
17
- I18n.t 'flash_validators.matchers.ensure_valid_hex_format_of.failure_message_for_should_not',
18
- model: model.class
16
+ I18n.t('flash_validators.matchers.ensure_valid_hex_format_of.failure_message_for_should_not', model: model.class)
19
17
  end
20
18
  end
@@ -9,12 +9,10 @@ RSpec::Matchers.define :ensure_valid_imei_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t 'flash_validators.matchers.ensure_valid_imei_format_of.failure_message_for_should',
13
- model: model.class
12
+ I18n.t('flash_validators.matchers.ensure_valid_imei_format_of.failure_message_for_should', model: model.class)
14
13
  end
15
14
 
16
15
  failure_message_when_negated do |model|
17
- I18n.t 'flash_validators.matchers.ensure_valid_imei_format_of.failure_message_for_should_not',
18
- model: model.class
16
+ I18n.t('flash_validators.matchers.ensure_valid_imei_format_of.failure_message_for_should_not', model: model.class)
19
17
  end
20
18
  end
@@ -9,12 +9,10 @@ RSpec::Matchers.define :ensure_valid_ip_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t 'flash_validators.matchers.ensure_valid_ip_format_of.failure_message_for_should',
13
- model: model.class
12
+ I18n.t('flash_validators.matchers.ensure_valid_ip_format_of.failure_message_for_should', model: model.class)
14
13
  end
15
14
 
16
15
  failure_message_when_negated do |model|
17
- I18n.t 'flash_validators.matchers.ensure_valid_ip_format_of.failure_message_for_should_not',
18
- model: model.class
16
+ I18n.t('flash_validators.matchers.ensure_valid_ip_format_of.failure_message_for_should_not', model: model.class)
19
17
  end
20
18
  end
@@ -9,12 +9,10 @@ RSpec::Matchers.define :ensure_valid_latitude_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t 'flash_validators.matchers.ensure_valid_latitude_format_of.failure_message_for_should',
13
- model: model.class
12
+ I18n.t('flash_validators.matchers.ensure_valid_latitude_format_of.failure_message_for_should', model: model.class)
14
13
  end
15
14
 
16
15
  failure_message_when_negated do |model|
17
- I18n.t 'flash_validators.matchers.ensure_valid_latitude_format_of.failure_message_for_should_not',
18
- model: model.class
16
+ I18n.t('flash_validators.matchers.ensure_valid_latitude_format_of.failure_message_for_should_not', model: model.class)
19
17
  end
20
18
  end
@@ -9,12 +9,10 @@ RSpec::Matchers.define :ensure_valid_longitude_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t 'flash_validators.matchers.ensure_valid_longitude_format_of.failure_message_for_should',
13
- model: model.class
12
+ I18n.t('flash_validators.matchers.ensure_valid_longitude_format_of.failure_message_for_should', model: model.class)
14
13
  end
15
14
 
16
15
  failure_message_when_negated do |model|
17
- I18n.t 'flash_validators.matchers.ensure_valid_longitude_format_of.failure_message_for_should_not',
18
- model: model.class
16
+ I18n.t('flash_validators.matchers.ensure_valid_longitude_format_of.failure_message_for_should_not', model: model.class)
19
17
  end
20
18
  end
@@ -9,12 +9,10 @@ RSpec::Matchers.define :ensure_valid_mac_address_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t 'flash_validators.matchers.ensure_valid_mac_address_format_of.failure_message_for_should',
13
- model: model.class
12
+ I18n.t('flash_validators.matchers.ensure_valid_mac_address_format_of.failure_message_for_should', model: model.class)
14
13
  end
15
14
 
16
15
  failure_message_when_negated do |model|
17
- I18n.t 'flash_validators.matchers.ensure_valid_mac_address_format_of.failure_message_for_should_not',
18
- model: model.class
16
+ I18n.t('flash_validators.matchers.ensure_valid_mac_address_format_of.failure_message_for_should_not', model: model.class)
19
17
  end
20
18
  end
@@ -9,12 +9,10 @@ RSpec::Matchers.define :ensure_valid_name_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t 'flash_validators.matchers.ensure_valid_name_format_of.failure_message_for_should',
13
- model: model.class
12
+ I18n.t('flash_validators.matchers.ensure_valid_name_format_of.failure_message_for_should', model: model.class)
14
13
  end
15
14
 
16
15
  failure_message_when_negated do |model|
17
- I18n.t 'flash_validators.matchers.ensure_valid_name_format_of.failure_message_for_should_not',
18
- model: model.class
16
+ I18n.t('flash_validators.matchers.ensure_valid_name_format_of.failure_message_for_should_not', model: model.class)
19
17
  end
20
18
  end
@@ -9,12 +9,10 @@ RSpec::Matchers.define :ensure_valid_password_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t 'flash_validators.matchers.ensure_valid_password_format_of.failure_message_for_should',
13
- model: model.class
12
+ I18n.t('flash_validators.matchers.ensure_valid_password_format_of.failure_message_for_should', model: model.class)
14
13
  end
15
14
 
16
15
  failure_message_when_negated do |model|
17
- I18n.t 'flash_validators.matchers.ensure_valid_password_format_of.failure_message_for_should_not',
18
- model: model.class
16
+ I18n.t('flash_validators.matchers.ensure_valid_password_format_of.failure_message_for_should_not', model: model.class)
19
17
  end
20
18
  end
@@ -9,12 +9,10 @@ RSpec::Matchers.define :ensure_valid_phone_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t 'flash_validators.matchers.ensure_valid_phone_format_of.failure_message_for_should',
13
- model: model.class
12
+ I18n.t('flash_validators.matchers.ensure_valid_phone_format_of.failure_message_for_should', model: model.class)
14
13
  end
15
14
 
16
15
  failure_message_when_negated do |model|
17
- I18n.t 'flash_validators.matchers.ensure_valid_phone_format_of.failure_message_for_should_not',
18
- model: model.class
16
+ I18n.t('flash_validators.matchers.ensure_valid_phone_format_of.failure_message_for_should_not', model: model.class)
19
17
  end
20
18
  end
@@ -9,12 +9,10 @@ RSpec::Matchers.define :ensure_valid_slug_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t 'flash_validators.matchers.ensure_valid_slug_format_of.failure_message_for_should',
13
- model: model.class
12
+ I18n.t('flash_validators.matchers.ensure_valid_slug_format_of.failure_message_for_should', model: model.class)
14
13
  end
15
14
 
16
15
  failure_message_when_negated do |model|
17
- I18n.t 'flash_validators.matchers.ensure_valid_slug_format_of.failure_message_for_should_not',
18
- model: model.class
16
+ I18n.t('flash_validators.matchers.ensure_valid_slug_format_of.failure_message_for_should_not', model: model.class)
19
17
  end
20
18
  end
@@ -9,12 +9,10 @@ RSpec::Matchers.define :ensure_valid_ssn_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t 'flash_validators.matchers.ensure_valid_ssn_format_of.failure_message_for_should',
13
- model: model.class
12
+ I18n.t('flash_validators.matchers.ensure_valid_ssn_format_of.failure_message_for_should', model: model.class)
14
13
  end
15
14
 
16
15
  failure_message_when_negated do |model|
17
- I18n.t 'flash_validators.matchers.ensure_valid_ssn_format_of.failure_message_for_should_not',
18
- model: model.class
16
+ I18n.t('flash_validators.matchers.ensure_valid_ssn_format_of.failure_message_for_should_not', model: model.class)
19
17
  end
20
18
  end
@@ -9,12 +9,10 @@ RSpec::Matchers.define :ensure_valid_url_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t 'flash_validators.matchers.ensure_valid_url_format_of.failure_message_for_should',
13
- model: model.class
12
+ I18n.t('flash_validators.matchers.ensure_valid_url_format_of.failure_message_for_should', model: model.class)
14
13
  end
15
14
 
16
15
  failure_message_when_negated do |model|
17
- I18n.t 'flash_validators.matchers.ensure_valid_url_format_of.failure_message_for_should_not',
18
- model: model.class
16
+ I18n.t('flash_validators.matchers.ensure_valid_url_format_of.failure_message_for_should_not', model: model.class)
19
17
  end
20
18
  end
@@ -9,12 +9,10 @@ RSpec::Matchers.define :ensure_valid_username_format_of do |attribute|
9
9
  end
10
10
 
11
11
  failure_message do |model|
12
- I18n.t 'flash_validators.matchers.ensure_valid_username_format_of.failure_message_for_should',
13
- model: model.class
12
+ I18n.t('flash_validators.matchers.ensure_valid_username_format_of.failure_message_for_should', model: model.class)
14
13
  end
15
14
 
16
15
  failure_message_when_negated do |model|
17
- I18n.t 'flash_validators.matchers.ensure_valid_username_format_of.failure_message_for_should_not',
18
- model: model.class
16
+ I18n.t('flash_validators.matchers.ensure_valid_username_format_of.failure_message_for_should_not', model: model.class)
19
17
  end
20
18
  end
@@ -0,0 +1,17 @@
1
+ class AlphaNumericValidator < ActiveModel::EachValidator
2
+
3
+ def validate_each(record, attribute, value)
4
+ strict_mode = options[:strict] || false
5
+
6
+ if strict_mode
7
+ format = /^[A-Za-z0-9]+$/i # Strict: requires no spaces to be included
8
+ else
9
+ format = /^[A-Za-z0-9 ]+$/i
10
+ end
11
+
12
+ unless value =~ format
13
+ record.errors[attribute] << (options[:message] || I18n.t('errors.messages.alpha_numeric'))
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,19 @@
1
+ class AlphaValidator < ActiveModel::EachValidator
2
+
3
+ def validate_each(record, attribute, value)
4
+ if options[:strict]
5
+ format = /^[A-Za-z]+$/i # Strict: requires no spaces to be included
6
+ elsif options[:lowercase]
7
+ format = /^[a-z]+$/
8
+ elsif options[:uppercase]
9
+ format = /^[A-Z]+$/
10
+ else
11
+ format = /^[A-Za-z ]+$/i
12
+ end
13
+
14
+ unless value =~ format
15
+ record.errors[attribute] << (options[:message] || I18n.t('errors.messages.alpha'))
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,25 @@
1
+ class CreditCardValidator < ActiveModel::EachValidator
2
+
3
+ def validate_each(record, attribute, value)
4
+ if options[:american_express]
5
+ format = /^3[47][0-9]{13}$/
6
+ elsif options[:diners_club]
7
+ format = /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/
8
+ elsif options[:discover]
9
+ format = /^6(?:011|5[0-9]{2})[0-9]{12}$/
10
+ elsif options[:jbc]
11
+ format = /^(?:2131|1800|35\d{3})\d{11}$/
12
+ elsif options[:master_card]
13
+ format = /^5[1-5][0-9]{14}$/
14
+ elsif options[:visa]
15
+ format = /^4[0-9]{12}(?:[0-9]{3})?$/
16
+ else
17
+ format = /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|6(?:011|5[0-9]{2})[0-9]{12}|(?:2131|1800|35\d{3})\d{11})$/
18
+ end
19
+
20
+ unless value.to_s =~ format
21
+ record.errors[attribute] << (options[:message] || I18n.t('errors.messages.credit_card'))
22
+ end
23
+ end
24
+
25
+ end