How can i use the validator “match” which validates that the attribute value matches to the specified regular expression????

I want to use the pattern which is the regular expression to be matched with…

but can you help me???

array('username', 'match', 'pattern'=>'/^[A-Za-z0-9_]+$/', 'message'=>'Invalid username!'),

Look at API for more details.


array('CODICE_FISCALE','match', 'pattern'=>'/^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/', 'message'=>'Codice Errato!')

But don’t work,the match with the expression don’t happen!!!

Add this to your rule


Edit: I tested with ‘AAAAAA12B34C567D’.


Don’t work the sameee…:(

i DON’T understand

Please describe in what way it doesn’t work. What test data do you use? Is it intentional that you only allow upper case letters? Perhaps you would want to add conversion before validation. Check what’s in $yourmodel->CODICE_FISCALE before you call validate/save (use echo, print_r or trace to the log).


Is as if the check there insn’t.

I insert a wrong value and places it anyway in my db…

this is the code in the model

array('CODICE_FISCALE','match', 'pattern'=>'/^[A-Za-z]{6}[0-9]{2}[A-Za-z]{1}[0-9]{2}[A-Za-z]{1}[0-9]{3}[A-Za-z]{1}$ /', 'message'=>'Codice Errato!','allowEmpty'=>false),

I have also changed the expression thinking that is wrong…but the result is the same!!!

What about your controller action? If you use save(false) no validation will take place.