add

Friday, May 17, 2013

Zend perks

Zend perks

1. StringLength Validator in Form
$this->addElement('text', 'password', array(
    'label' => 'Password:',
    'required' => true,
    'filters' => array('StringTrim'),
    'validators' => array(
        array('StringLength', false, array(8,20))
    )
));
Another way doing the same thing
$this->addElement('textarea', 'comment', array(  
    'label' => 'Please Comment:',  
    'required' => true,  
    'validators' => array(  
        array('validator' => 'StringLength', 'options' => array(0, 20))  
    )  
)); 

2. Regular expression

To use a regular expression in zend you regex mus b enclosed in (/) like /regex/
$this->addElement('text', 'password', array(
    'label' => 'Password:',
    'required' => true,
    //'filters' => array('StringTrim'),
    'validators' => array(
        array('StringLength', false, array(8,20)),
        array('regex', false, array('pattern' => '/^\S*(?=\S{8,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])\S*$/'))
    )
));


No comments:

Post a Comment