Skip to content

Instantly share code, notes, and snippets.

@mozamimy
Created May 4, 2015 07:43
Show Gist options
  • Save mozamimy/52c0004c8370f78df2c2 to your computer and use it in GitHub Desktop.
Save mozamimy/52c0004c8370f78df2c2 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
@jprosevear
Copy link

jprosevear commented Mar 23, 2022

FFaker::Internet.mac provides lower case letters:

/\A([0-9A-Fa-f]{2}[-:]){5}([0-9A-Fa-f]{2})\z/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment