Exemplo n.º 1
0
 public function testMAC()
 {
     $inputs = array(array('mac' => '', 'res' => false), array('mac' => '00:11:22:33:44:55', 'res' => true), array('mac' => '00-11-22-33-44-55', 'res' => true), array('mac' => '001122334455', 'res' => true), array('mac' => '0011223344', 'res' => false), array('mac' => '00:11:22:33::55', 'res' => false), array('mac' => '00:11:22:33', 'res' => false), array('mac' => '00:ae:fe:23:45:F4', 'res' => true));
     foreach ($inputs as $i) {
         $mac = $i['mac'];
         $res = $i['res'];
         try {
             $w = validator\Net::macAddress($mac);
         } catch (Invalid $e) {
             if (!$res) {
                 continue;
             }
             $this->fail(sprintf('This value should be good: %s.', $mac));
         }
         if (!$res) {
             $this->fail(sprintf('This value should be bad: %s.', $mac));
         }
     }
 }
Exemplo n.º 2
0
 public function __construct($params = array())
 {
     parent::__construct($params);
     $this->validators[] = function ($value) {
         return validator\Net::macAddress($value);
     };
     $this->widget->attrs['pattern'] = '([0-9A-Fa-f]{2}[:-]{0,1}){5}[0-9A-Fa-f]{2}';
 }