Sha256: 072b3c87e6f43612e4ce80c4f44cb3d707754d151ac604cd822e1236ab3c5bb3

Contents?: true

Size: 855 Bytes

Versions: 1

Compression:

Stored size: 855 Bytes

Contents

require 'validator/generic_validator'

module Owasp
  module Esapi
    module Validator
      
      # This is a validator class for zip codes.
      class Zipcode < GenericValidator
      
        ITALIAN_ZIPCODE = "^\\d{5}$"
        US_ZIPCODE = "^\\d{5}(\\-\\d{4})?$"
        
        # Creates a new Zipcode validator.
        # @param custom_regex if you don't find your locale zip code regular expression, you can provide a 
        # very custom one
        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
        
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
owasp-esapi-ruby-0.30.0 lib/validator/zipcode.rb