Created
July 17, 2011 02:30
-
-
Save TiuTalk/1087056 to your computer and use it in GitHub Desktop.
Criando um método de validação
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
| <?php | |
| class Usuario extends AppModel { | |
| public $name = 'Usuario'; | |
| public $validate = array( | |
| 'twitter' => array( | |
| 'rule' => 'perfilTwitter', | |
| 'message' => 'Perfil do Twitter inválido' | |
| ) | |
| ); | |
| public function perfilTwitter($data) { | |
| $perfil = array_shift($data); | |
| // Letras, números e _ | |
| $pattern = '/@([A-Za-z0-9_]+)/'; | |
| return preg_match($pattern, $perfil); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment