Aadhar Number Validator

2 2
1
Viewed: 123 956 times
Version: 2.0
Category: Tips
Written by: shiv shiv
Created: Sep 27, 2022

You are viewing revision #1 of this wiki article.
This is the latest version of this article.

In India have Aadhar number an we may need to valid it a input. So I created a validator for yii2

use yii\validators\Validator;

class TAadharNumberValidator extends Validator
{

    public $regExPattern = '/^\d{4}\s\d{4}\s\d{4}$/';

    public function validateAttribute($model, $attribute)
    {
        if (preg_match($this->regExPattern, $model->$attribute)) {
            $model->addError($attribute, 'Not valid Aadhar Card Number');
        }
    }
}