Created
August 25, 2015 14:41
-
-
Save namuit/039ef8aa91dd5ff2b51c to your computer and use it in GitHub Desktop.
Italian Postcode validator for Ruby on Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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