Just another WordPress.com site

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*$/'))
)
));
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: