Thank you Anthony! You saved my Sunday! It worked! now I understand the meaning of provider and namespace.
Thank you very much again. I hope I can help you in the future too.
best regards,Thank you very much again. I hope I can help you in the future too.
2015-06-14 17:03 GMT-03:00 Anthony GRASSIOT <antograssiot@gmail.com>:
Paulo, this is what I'm doing with french phone number. I've cut the example to the minimum :file src/Model/Validation/<?php
namespace App\Model\Validation;
class FrValidationRule
{
public static function phone($check) {
$pattern = '/^0[1-9]{1}(([0-9]{2}){4})|((\s[0-9]{2}){4})|((-[0-9]{2}){4})|((\.[0-9]{2}){4})$/';
return (bool)preg_match($pattern, $check);
}
}and then in the table :public function validationDefault(Validator $validator){
$validator->provider('french', 'App\Model\Validation\FrValidationRule');
$validator
->add('phone', 'phone', [
'rule' => 'phone',
'provider' => 'french',
'message' => __('Merci d\'entrer un numéro de téléphone valide.')
]);
return $validator;
}I hope it will help.best regards
Le vendredi 12 juin 2015 13:06:04 UTC+2, Paulo Terra a écrit :Hi, I have been looking for a plugin to validate Person ID, Phone, ZIP Code, etc, but all I can find is for old versions of CakePHP. Does anybody know where I can find a working version for CakePHP 3.0?
Thanks.
Paulo Terra--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to a topic in the Google Groups "CakePHP" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cake-php/Zn05icCM6rQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment