Skip to content

Instantly share code, notes, and snippets.

@namuit
Created August 25, 2015 14:41
Show Gist options
  • Save namuit/039ef8aa91dd5ff2b51c to your computer and use it in GitHub Desktop.
Save namuit/039ef8aa91dd5ff2b51c to your computer and use it in GitHub Desktop.
Italian Postcode validator for Ruby on Rails
class CapValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value =~ /^(V-|I-)?[0-9]{5}$/
record.errors[attribute] << (options[:message] || "postcode not valid")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment