Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lbvf50mobile/a90665a0e927a1be009706fe6ca2bc7a to your computer and use it in GitHub Desktop.
Save lbvf50mobile/a90665a0e927a1be009706fe6ca2bc7a to your computer and use it in GitHub Desktop.
Validations for IP address and MAC address on Ruby on Rails
require "resolv"
class Model < ActiveRecord::Base
validates :ip_address, format: { with: Resolv::IPv4::Regex }
validates :mac_address, format: { with: /\A([0-9A-F]{2}[-:]){5}([0-9A-F]{2})\z/ }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment