Module: ViaCep::Validators::Zipcode
- Defined in:
- lib/via_cep/validators.rb
Overview
Zipcode validator
Class Method Summary collapse
-
.valid?(zipcode) ⇒ Boolean
Validates if the zipcode passed is a valid one.
Class Method Details
.valid?(zipcode) ⇒ Boolean
Validates if the zipcode passed is a valid one.
Return if is valid or not
ViaCep::Validators::Zipcode.valid?('0')
#=> false
ViaCep::Validators::Zipcode.valid?('01001000')
#=> true
return Boolean
42 43 44 45 |
# File 'lib/via_cep/validators.rb', line 42 def valid?(zipcode) zipcode = zipcode.to_s !!zipcode.match(/^[0-9]{5}(-)[0-9]{3}$/) || !!zipcode.match(/^[0-9]{8}$/) end |