validate mac address field

Hi to all,

i'd like to insert a validation inside my model about a mac address
field.
I've used this sintax but it's not working.

validates_format_of :mac_address, :with =>
/^((?:[-a-f0-9])+(?:[-a-f0-9])+(?:[-a-f0-9])+(?:[-a-f0-9])+(?:[-a-f0-9])+(?:[-a-f0-9]))$/i,
                                          :on => :create,
                                          :on => :update,
                                          :message => "MAC ADDRESS
incorrect"

this code it's not working, i'm looking for a solution but i can't find
out the problem...

Any help will be great...

Thanks

Andre

Try with this regexp:

/^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$/i

irb(main):001:0> '00:09:6B:DF:FE:42' =~
/^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$/i
=> 0

Emilio Tagua wrote:

irb(main):001:0> '00:09:6B:DF:FE:42' =~
/^([0-9a-fA-F]{2}[:-]){5}[0-9a-fA-F]{2}$/i
=> 0

Hi Emilio,

thanks too much...
It works :wink: