Created
August 6, 2014 20:37
-
-
Save carlosfilho88/b65b845007041e428cf6 to your computer and use it in GitHub Desktop.
Custom validators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$email = new Zend_Form_Element_Text('email'); | |
$email->setLabel('E-mail') | |
->addFilter('stringTrim') | |
->setAttribs(array('onDrag' => 'return false', 'onDrop' => 'return false', 'onPaste' => 'return false', 'autocomplete' => 'off', 'class'=>'input-xlarge')) | |
->setRequired(true) | |
->addValidators(array(array('EmailAddress'),array('Db_RecordExists', false, array('table' => 'usuarios','field' => 'email')))) | |
->addErrorMessages(array(Zend_Validate_Db_RecordExists::ERROR_RECORD_FOUND => 'O e-mail informado não está cadastrado.')); | |
$cpf = new Zend_Form_Element_Text('cpf'); | |
$cpf->setValidators(array(array('StringLength', false, array(14, 14)))) | |
->setAttrib('maxlength', 14) | |
->setAttrib('class', 'input-xlarge') | |
->setRequired(true) | |
->addValidator('regex', false, array( | |
'pattern' => '/^([0-9]{3}\.){2}[0-9]{3}-[0-9]{2}$/i', | |
'messages' => array('regexInvalid' => "Este CPF é inválido", | |
'regexNotMatch' => "'%value%' não coincide com o formato '999.999.999-99'", | |
'regexErrorous' => "Ocorreu um erro inesperado na validação, tente novamente."))) | |
->setLabel('CPF') | |
->addFilter('stringTrim') | |
->addValidator(new Util_ValidateCPF()) | |
->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => 'Informe o CPF'))) | |
->addValidators(array(array('Db_RecordExists', false, array('table' => 'usuarios', 'field' => 'cpf' )) )) | |
->getValidator('Db_RecordExists')->setMessage('O CPF informado não está cadastrado.'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment