luhn-number-validator Validates Luhn numbers used in all kinds of number (ICCID, IMEI, ...)

  1. LuhnNumberValidator - Validates Luhn numbers
  2. Requirements
  3. Usage

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).
2 0
4 followers
349 downloads
Yii Version: 1.1
License: BSD-2-Clause
Category: Validation
Developed by: le_top
Created on: Dec 26, 2013
Last updated: 9 years ago

Downloads

show all

Related Extensions