Class: ItalianPersonalTaxCodeValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ItalianPersonalTaxCodeValidator
- Defined in:
- lib/active_model/validations/italian_personal_tax_code_validator.rb
Overview
Thanks to github.com/freego/italian_job
Constant Summary collapse
- REGEX =
Regexp.compile('\A[A-Z]{6}[0-9]{2}[A-Z][0-9]{2}[A-Z][0-9]{3}[A-Z]\z')
- BUSINESS_REGEX =
Regexp.compile('\A(?:IT)?[0-9]{11}\z')
- DISPARI =
[1, 0, 5, 7, 9, 13, 15, 17, 19, 21, 1, 0, 5, 7, 9, 13, 15, 17, 19, 21, 2, 4, 18, 20, 11, 3, 6, 8, 12, 14, 16, 10, 22, 25, 24, 23].freeze
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/active_model/validations/italian_personal_tax_code_validator.rb', line 12 def validate_each(record, attribute, value) return if [:allow_blank] && value.blank? return if allow_vat_numbers?(record) && value.match(BUSINESS_REGEX) record.errors.add(attribute, :invalid) unless control_code_valid?(value) end |