RegexValidator

Hello,

sorry in advance for stupid question but i just cant find answer in docs:

could anyone post an example on how to set rules in activeRecord class, to achieve Regex pattern validation for some attribute.

i mean something like:





	public function rules()

	{

		return array(

			array('attribute','pattern'=>'someRegexPattern'),

		);

	}



so could you post an example rules array also with some easy sample regex (lets say email regex)?

any help highly appreciated

Smeto

If you want an email validator you can simply use the email validator :)

The pattern you be provided as follows: ‘/<your pattern>/’. For example:




 public function rules()

        {

                return array(

                        array('attribute','pattern'=>'/[a-zA-Z0-9]{2,}/'),

                );

        }



The given pattern requires at least to alphanumeric characters.

next answer

vvvvvvvvvv

This is in rules():

array(‘content’, ‘application.extensions.urivalidator.EUriValidator’, ‘mode’=>‘web’)

This is how I am using the URI Validation Extension. The “'application.extensions.urivalidator.EUriValidator” points to a file with a method with something like


if (!preg_match("/^(https?):\/\/(?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />(?:[a-z0-9\-\._\~!\$\&\'\(\)\*\+\,\;\=\:]|%[0-9A-F]{2})*)\@)?((?:[a-z0-9\.\-]|%[0-9A-F]{2}){3,})(?:<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />\d+))?((?:\/(?:[a-z0-9\-\.\_\~\!\$\&\'\(\)\*\+\,\;\=\:\@]|%[0-9A-F]{2})*)*)(?:\?((?:[a-z0-9\-\.\_\~\!\$\&\'\(\)\*\+\,\;\=\:\/\?\@]|%[0-9A-F]{2})*))?(?:\#((?:[a-z0-9\-\.\_\~\!\$\&\'\(\)\*\+\,\;\=\:\/\?\@]|%[0-9A-F]{2})*))?$/i", $uri, $parts)) {

         return false;

      }

The ‘mode’=>‘web’ picks which method to use in that file.

Content is the thing to be checked

thanx a lot man, it worked the same way for my problem…:)