Yii Framework Forum: CRegularExpressionValidator - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CRegularExpressionValidator Rate Topic: -----

#1 User is offline   kitty10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 13-April 10

Posted 13 May 2010 - 08:52 AM

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???
0

#2 User is offline   andy_s 

  • Random Member Title
  • Yii
  • Group: Moderators
  • Posts: 1,526
  • Joined: 22-June 09
  • Location:Russia, Kostroma

Posted 13 May 2010 - 09:08 AM

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

Look at API for more details.
0

#3 User is offline   kitty10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 13-April 10

Posted 13 May 2010 - 09:27 AM

View Postandy_s, on 13 May 2010 - 09:08 AM, said:

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

Look at API for more details.


MY CODE IS:
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!!!
0

#4 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 13 May 2010 - 10:23 AM

View Postkitty10, on 13 May 2010 - 09:27 AM, said:

MY CODE IS:
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
'allowEmpty'=>false, 


Edit: I tested with 'AAAAAA12B34C567D'.

/Tommy

This post has been edited by tri: 13 May 2010 - 10:36 AM

Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#5 User is offline   kitty10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 13-April 10

Posted 13 May 2010 - 10:44 AM

View Posttri, on 13 May 2010 - 10:23 AM, said:

Add this to your rule
'allowEmpty'=>false, 


Edit: I tested with 'AAAAAA12B34C567D'.

/Tommy

Don't work the sameee..:(
i DON'T understand
0

#6 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 13 May 2010 - 11:12 AM

View Postkitty10, on 13 May 2010 - 10:44 AM, said:

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).

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#7 User is offline   kitty10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 13-April 10

Posted 14 May 2010 - 04:46 AM

View Posttri, on 13 May 2010 - 11:12 AM, said:

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).

/Tommy

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!!!
0

#8 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 14 May 2010 - 05:20 AM

View Postkitty10, on 14 May 2010 - 04:46 AM, said:

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.

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users