сrib on validators in Yii2

yii2_validator_model_rules

A list of commonly needed validators in yii2
 

 public function rules()
    {
        return [
            ['name', 'required'],
            [['surname','name','email'],'required'],
            ['surname','default'],
            ['surname', 'default', 'value' => '...'],
            ['name_pattern', 'match', 'pattern' => '/^[a-zA-Z]+$/'],
            ['username', 'unique', 'targetClass' => self::className(), 'message' => '...'],
            ['username', 'string', 'min' => 2, 'max' => 255],
            ['newPasswordRepeat', 'compare', 'compareAttribute' => 'newPassword'],
            ['Password', 'validatePassword'],
            ['email', 'email'],
            ['active', 'boolean'],
            ['status', 'integer'],
            ['status', 'in', 'range' => [3, 4, 5]],
            ['date', 'date', 'format' => 'php:Y-m-d'],
            ['url', 'url'],
            ['link', 'url', 'defaultScheme' => 'http'],
            ['search', 'filter', 'filter' => 'trim'],
            ['blank','file','skipOnEmpty'=>false, 'extensions' => 'jpg',
             'maxSize' => 412000, 'tooBig' => 'Limit is 400KB'],
            ['safeAttribute', 'safe'],
            ['verifyCode', 'captcha','captchaAction' => '....'],
        ];
    }


 public function validatePassword($attribute, $params)
    {
        if (!$this->hasErrors()) {
          ................
        }
    }
Timothydom
Feb 9, 2018, 10:01:22 PM
Timothydom I am typically to running a blog and i actually recognize your content. The article has really peaks my interest. I am going to bookmark your web site and keep checking for new information.
Samvel Sargsyan
Feb 12, 2018, 2:04:01 AM
Samvel Sargsyan Thank you

Comment