Class: BrRailties::CnpjValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- BrRailties::CnpjValidator
- Defined in:
- app/validators/br_railties/cnpj_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'app/validators/br_railties/cnpj_validator.rb', line 7 def validate_each(record, attribute, value) cnpj = ::CNPJ.new(value) return if cnpj.valid? && value == cnpj.stripped record.errors.add( attribute, [:message] || 'CNPJ inválido (14 caracteres, somente dígitos)' ) end |