2016-05-19 143 views

回答

0

a StringLength validator for ZF2

$value = '123456789'; 
$validator = new \Zend\Validator\StringLength(array('max' => 9, 'min' => 9)); 
$validator->isValid($value); // returns true 

要檢查數值不僅可以使用the Digits validator

$value = '123456789'; 
$validator = new \Zend\Validator\Digits(); 
$validator->isValid($value); // returns true 

所以,你的「號碼」您輸入濾波器配置裏面輸入看起來是這樣的:

'number' => array(
    'name' => 'number', 
    'required' => true, //or false 
    'filters' => array(
    ), 
    'validators' => array(
     array(
      'name' => 'StringLength', 
      'options' => array(
       'min' => 9, 
       'max' => 9 
      ) 
     ), 
     array(
      'name' => 'Digits', 
     ) 
    ) 
),