Class: TaiwanValidator::AddressValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- TaiwanValidator::AddressValidator
- Defined in:
- lib/taiwan_validator/address_validator.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.valid?(address) ⇒ Boolean
3 4 5 |
# File 'lib/taiwan_validator/address_validator.rb', line 3 def valid?(address) /(\A\d{3,5})?\s?(\D+[縣市])(\D+[鄉鎮市區])?(.+)/.match(address) end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
8 9 10 11 12 |
# File 'lib/taiwan_validator/address_validator.rb', line 8 def validate_each(record, attribute, value) unless self.class.valid?(value) record.errors.add(attribute, [:message] || :invalid) end end |