class IpValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless value =~ /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ record.errors[attribute] << (options[:message] || I18n.t('yukonisuru.errors.messages.ip')) end end end