CakePHP 3.0 - Regular expression validation

I need to validate an input based on a regular expression.

 //Validator
 $validator
            ->notEmpty('sl_no')
            ->add('reg_no', 'validFormat',[
                    'rule' => '/^([ABCD]{2,2}[0-9]{4,4})$/i',
                    'message' => 'Please enter a valid serial number.'
            ]);

But I get the following error:

Method /^([ABCD]{2,2}[0-9]{4,4})$/i does not exist.

Also, there is no mention of regular expressions in Cake 3.0 validation Documentation unlike Cake 2 Documentation.

Has this been moved or modified?

Answers


Try this

 $validator
        ->notEmpty('sl_no')
        ->add('reg_no', 'validFormat',[
                'rule' => array('custom', '/^([ABCD]{2,2}[0-9]{4,4})$/i'),
                'message' => 'Please enter a valid serial number.'
        ]);

Need Your Help

Errno 9 using the multiprocessing module with Tornado in Python

python callback multiprocessing tornado ioerror

For operations in my Tornado server that are expected to block (and can't be easily modified to use things like Tornado's asynchronous HTTP request client), I have been offloading the work to separ...

How can I save semantic information in a MySQL table?

mysql database semantics

I wish to save some semantic information about data in a table. How can I save this information in MySQL, such that I can access data and also search for the articles using the semantic data.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.