Skip to content

Instantly share code, notes, and snippets.

@geoffgarside
geoffgarside / ip_address_validator.rb
Created November 4, 2011 14:55
Rails 3.x IP Address validator class
# The IP Address Validator accepts the following options
#
# * allow_nil - allows nil values
# * allow_blank - allows blank values
# * allow_cidr - allows /prefixlen CIDR masks in values
#
# the validator will use regular expressions in an attempt to prevent
# malformed IP addresses from being passed to the IPAddr.new initializer
# as this method can be very slow to raise exceptions for malformed input.
class IpAddressValidator < ActiveModel::EachValidator