yii-codice-fiscale-validator

Simple class to validate the Italian tax code
2 followers

Codice Fiscale (tax code or CF) is the italian code used to uniquely identify citizens for tax and administrative purpose

This is a simple class that validates and generates the Italian tax code (codice fiscale)

GitHub Repository

Usage in active record

class Citizen extends CActiveRecord
{
    [...]
    public function rules()
    {
        return array(
            [...]
            array('tax_code', 'ext.CfValidator',
                'strict' => true,
                'validateWithAttrs' => array( // key value pairs [modelattributes => CfValidator local properties]
                    'nome' => 'name',
                    'cognome' => 'surname',
                    'genere' => 'gender',
                    'giorno_nascita' => 'dayOfBirth',
                    'mese_nascita' => 'monthOfBirth',
                    'anno_nascita' => 'yearOfBirth',
                    'comune_nascita' => 'codeIstat',
                )
            )
 
        );
    }
    [...]
}

Static usage

Yii::import('ext.CfValidator');
$cf = new CfValidator();
$cf->strict = true;
$cf->gender = CfValidator::GENDER_MALE;
$cf->name = 'Mario';
$cf->surname = 'Rossi';
$cf->dayOfBirth = '01';
$cf->monthOfBirth = '01';
$cf->yearOfBirth = '1980';
$cf->codeIstat = 'H501';
 
if(!$cf->validateValue("MRARSS80A01H501T") {
    echo "Error TAX CODE shoud be: " . $cf->cf
}

Todo

  • Client Validation

Total 2 comments

#16495 report it
toriphes at 2014/02/28 03:15am
omocodia

Ciao Peppe, il validatore non considera i casi di omocodia. Tutta via è possibile effettuare solo una validazione di forma anziché di contenuto, basta non abilitare il flag $strict.

#16493 report it
Peppe at 2014/02/28 02:47am
omocodia

Tiene conto dei casi di omocodia?

Leave a comment

Please to leave your comment.

Create extension