Created
July 12, 2011 15:46
-
-
Save nickyp/1078240 to your computer and use it in GitHub Desktop.
validate_ip_address
This file contains 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
def validate_ip_address | |
valid_ip_address = begin; IP.new(self.ip_address); rescue; end | |
unless ignore_nil{ valid_ip_address.is_a?(IP::V4) } | |
if target == "appliance" | |
self.errors.add_to_base I18n.t(:invalid_ipv4, :scope => | |
TRANSLATE_BASE_SCOPE, :ip_address => self.ip_address) | |
else | |
self.errors.add(:ip_address, I18n.t(:invalid_ipv4, :scope => | |
TRANSLATE_BASE_SCOPE, :ip_address => self.ip_address)) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment