Class: ActiveModel::Validations::CodiceFiscaleFormatValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::CodiceFiscaleFormatValidator
- Defined in:
- lib/italian_job/validators/codice_fiscale_format.rb
Constant Summary collapse
- REGEX =
Regexp.compile("^[A-Z]{6}[0-9]{2}[A-Z][0-9]{2}[A-Z][0-9]{3}[A-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]
Instance Method Summary collapse
Instance Method Details
#validate_each(object, attribute, value) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/italian_job/validators/codice_fiscale_format.rb', line 8 def validate_each(object, attribute, value) if value.blank? object.errors[attribute] << I18n.translate("activerecord.errors.codice_fiscale.empty") return end unless value.match(REGEX) object.errors[attribute] << I18n.translate("activerecord.errors.codice_fiscale.invalid_format") return end unless control_code_valid?(value) object.errors[attribute] << I18n.translate("activerecord.errors.codice_fiscale.invalid_format") return end end |