override core rules in yii2 -


i wanted override core rule number in yii2 convert persian numbers english numbers, , validate them? these code uses converting persian numbers english numbers in php

function convert($string) {     $persian = array('۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹');     $num = range(0, 9);     return str_replace($persian, $num, $string); } 

how can apply these codes doing convert before validation?i don't want use beforevalidate in model wrote componet don't know function , should change?

add filter rule in model.

public function rules() {     return [         ['pers_number', 'filter', 'filter' => function ($value) {             return str_replace(                 ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'],                  range(0, 9),                 $value             );         }],     ]; } 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

Laravel mail error `Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [ #0]` -

c# SetCompatibleTextRenderingDefault must be called before the first -