Created
May 4, 2015 07:43
-
-
Save mozamimy/52c0004c8370f78df2c2 to your computer and use it in GitHub Desktop.
Validations for IP address and MAC address on Ruby on Rails
This file contains hidden or 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
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
FFaker::Internet.mac provides lower case letters:
/\A([0-9A-Fa-f]{2}[-:]){5}([0-9A-Fa-f]{2})\z/