Skip to content

Instantly share code, notes, and snippets.

@alexshelkov
Created October 30, 2012 20:49
Show Gist options
  • Save alexshelkov/3982938 to your computer and use it in GitHub Desktop.
Save alexshelkov/3982938 to your computer and use it in GitHub Desktop.
$factory = new \Zend\InputFilter\Factory();
$i = $factory->createInputFilter(array(
'password' => array(
'name' => 'password',
'required' => true,
'validators' => array(
array(
'name' => 'not_empty',
),
array(
'name' => 'string_length',
'options' => array(
'min' => 8
),
),
),
),
));
$i->setData(array('password' => 'test'));
var_dump($i->isValid()); // false
// this is not required, but also may help,
// if you haven't got any "password" in your data it will be valid. But if it in data, it would not
$i->get('password')->setRequired(false);
// remove all validators
$i->get('password')->setValidatorChain(new \Zend\Validator\ValidatorChain());
var_dump($i->isValid()); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment