Class: BsnValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- BsnValidator
- Defined in:
- lib/elfproef/bsn_validator.rb
Overview
Validates if the specified value is a valid Burgerservicenummer (Dutch social security number)
Class Method Summary collapse
-
.validate_bsn(value, options = {}) ⇒ Object
A BSN is an 8 or 9 digit Dutch social security number.
Instance Method Summary collapse
Class Method Details
.validate_bsn(value, options = {}) ⇒ Object
A BSN is an 8 or 9 digit Dutch social security number.
15 16 17 18 19 20 21 22 23 |
# File 'lib/elfproef/bsn_validator.rb', line 15 def self.validate_bsn(value, = {}) bsn = value.to_s.gsub(/\D/, '').strip # Only allow 8 or 9 digits return false if bsn.length < 8 || bsn.length > 9 # Validate with the advanced eleven test self.validate_with_advanced_eleven_test(bsn) end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
7 8 9 10 11 |
# File 'lib/elfproef/bsn_validator.rb', line 7 def validate_each(record, attribute, value) unless self.class.validate_bsn(value, ) record.errors.add(attribute, :invalid_bsn, ) end end |