LuhnNumberValidator - Validates Luhn numbers ¶
Numbers like IMEI, ICCID, French SIREN, French SIRET, visa, ... can be checked with this extension.
Requirements ¶
Works with Yii 1.11 and above (and probably below).
Usage ¶
Use this validator as most validators.
In rules of a model, do:
public function rules() {
return array(
array( 'imei','LuhnNumber',
'type'=>'IMEI',
'allowEmpty'=>false,
/* 'length'=>19, 'pattern'=>'/^\d+$/' */
),
);
}
Where:
- 'imei' is the name of the attribute (or attribute list)
- 'type' is the type of the number ('IMEI', 'ICCID', 'SIRET', 'SIREN', or none)
- 'allowEmpty' if the value can be empty or not
- 'length' length of the number (if absent: any length if not given by 'type')
- 'pattern' pattern that the number must match (default match=number of digits expected in length).
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.