我在我的项目中使用下面的代码通过电话号码进行验证,
$phone = new Zend_Form_Element_Text('phone', array(
'label' => $view->_('phone'),
'value' => '',
'class' => 'text-size text hastip',
'title' => $qtips_messages['key_phone'],
'required' => true,
'tabindex' => '13',
'validators' => array(
array('Digits', false, array(
'messages' => array(
'notDigits' => "Phone Invalid Digits, ex. 1234567890",
'digitsStringEmpty' => "",
))),
array('notEmpty', true, array(
'messages' => array(
'isEmpty' => 'Phone can\'t be empty'
)
)),
array('StringLength', false, array(10, 10, 'messages' => array(
'stringLengthInvalid' => "Phone Length Invalid entry",
'stringLengthTooShort' => "Phone Invalid Length , ex. 1234567890"
))),
),
'filters' => array('StringTrim'),
'decorators' => $this->requiredElementDecorators,
'description' => '<img src="'.$baseurl.'/images/star.png" alt="required" />',
'filters' => array('StringTrim')
));
$this->addElement($phone);
当字段为空、无效、长度时,这很有效。我的要求是,电话字段也应该接受空格123 456 7890
。请就此提出建议。