Just wanted to add that instead of writing your own pattern you can use the build in one Resolv::IPv4::Regex
require 'resolv'
validates :gateway, :presence => true, :uniqueness => true,
:format => { :with => Resolv::IPv4::Regex }
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…