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.

Revisions

  1. namuit created this gist Aug 25, 2015.
    8 changes: 8 additions & 0 deletions cap_validator.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    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