Yii 1.1: fmac-validator

MAC-adress Syntax Validation

FMACValidator verifies if the attribute is not a valid MAC address.

The validator check the 3 standard (IEEE 802) formats:

  • Windows format mac address (example: 0a-1b-3c-4d-5e-6f)
  • Unix format mac address (example: 0a:1b:3c:4d:5e:6f)
  • CISCO format mac address (example: 0018.f352.d31c)


  • Yii 1.1.7 or above...


  • Extract the release file under protected/extensions/validators
  • Extract the message file under protected if you wish user messages in your language and translate the messages in your language.


In the model we use:

public function rules()
   return array(
        //allow all 3 standard (IEEE 802) formats
        array('<attributeName>', 'ext.validators.FMACValidator'),
        //allow only Windows format mac address
        //array('<attributeName>', 'ext.validators.FMACValidator','format'=>'windows'),
        //allow only Unix format mac address
        //array('<attributeName>', 'ext.validators.FMACValidator','format'=>'unix'),
        //allow only CISCO format mac address
        //array('<attributeName>', 'ext.validators.FMACValidator','format'=>'cisco'),

Configuration parameters

Parameter Default value Comment
attributes list (array)) of attributes to be validated
message the user-defined error message
on List of scenarios that the validator should be applied. Each array value refers to a scenario name with the same name as its array key.
safe true whether attributes listed with this validator should be considered safe for massive assignment
enableClientValidation true whether to perform client-side validation
allowEmpty true whether the attribute value can be null or empty
not false whether to invert the validation logic. If set to true, the regular expression defined should NOT match the attribute value.
format all allowed MAC format


Total 2 comments

#12787 report it
Trejder at 2013/04/12 04:02am

You can write your own, custom checking function, that will itself validate for only these two formats, you'll looking for. Just take a look to any auto-generated Yii app, into protected/models/LoginForm.php class, to rules() function, how authenticate filter is implemented there.

#7708 report it
Maxxer at 2012/04/11 03:59am
more than one format

it would be great to be able to allow TWO formats (i.e. unix and windows, but not cisco)

Leave a comment

Please to leave your comment.

Create extension