Sha256: baa003bbbe435d9439c338bec252ea5433787e96804d7342e30fec645b4e84e3
Contents?: true
Size: 471 Bytes
Versions: 1
Compression:
Stored size: 471 Bytes
Contents
class AddressValidator < ActiveModel::EachValidator # "(?<zipcode>(^\d{5}|^\d{3})?)(?<city>\D+[縣市])(?<district>\D+?(市區|鎮區|鎮市|[鄉鎮市區]))(?<others>.+)" class << self def valid?(address) /(\A\d{3,5})?\s?(\D+[縣市])(\D+[鄉鎮市區])?(.+)/.match(address) end end def validate_each(record, attribute, value) unless self.class.valid?(value) record.errors.add(attribute, options[:message] || :invalid) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
taiwan_validator-1.2.0 | lib/address_validator.rb |