A simple regex based exhaustive validator for PIN codes in India
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
india-pincode-regex/src/pincode_validator.rb

23 lines
426 B

require "pincode_validator/version"
module PincodeValidator
VERSION = "1.0.3"
FILENAME='regex.txt'
class Error < StandardError; end
def self.root
File.dirname __dir__
end
@@regexes ||= IO.readlines(File.join root, FILENAME).map do |line|
Regexp.new("^#{line.strip[1...-1]}$")
end
def self.valid?(pincode)
@@regexes.each do |r|
return true if r.match? pincode
end
false
end
end