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');
}
}
}
I will not recommend this validation for professional use. For example the aadhaar number 0000 0000 0000 will be validate as true.
public $regExPattern = '/^[2-9]{1}[0-9]{3}[0-9]{4}[0-9]{4}$/';
If you use this It Will Be Work Perfect and it will be show error for this For example the aadhaar number 0000 0000 0000
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.