Class: Owasp::Esapi::Validator::Zipcode

Inherits:
GenericValidator show all
Defined in:
lib/validator/zipcode.rb

Overview

This is a validator class for zip codes.

Constant Summary collapse

ITALIAN_ZIPCODE =
"^\\d{5}$"
US_ZIPCODE =
"^\\d{5}(\\-\\d{4})?$"

Instance Attribute Summary

Attributes inherited from GenericValidator

#matcher

Instance Method Summary collapse

Methods inherited from GenericValidator

#valid?

Constructor Details

#initialize(options = nil) ⇒ Zipcode

Creates a new Zipcode validator. very custom one

Parameters:

  • custom_regex

    if you don't find your locale zip code regular expression, you can provide a


16
17
18
19
20
21
22
# File 'lib/validator/zipcode.rb', line 16

def initialize(options = nil)
  # Matcher is tuned to match a valid US ZIP CODE, that means either 5 numbers, or 5 numbers, 
  # plus a dash, then 4 more numbers.
  @matcher = US_ZIPCODE
  @matcher = options["custom_regex"] unless (options.nil? || ! options.has_key?("custom_regex"))
  super(@matcher)
end