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

On Jan 18, 2008 3:03 PM, Andrea C.
[email protected] wrote:

                                      :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…

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 T. 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:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs