Zend - The PHP Company




Algorithms

Add Code


Check israeli Teudat Zehut number  

Type: code fragment
Added by: ols
Entered: 12/08/2003
Last modified: 06/12/2008
Rating: - (fewer than 3 votes)
Views: 5457
Checks validity of Israeli interim ID number (teudat zehut) using algorithm described in http://www.halemo.com/info/idcard (the link in Hebrew).


<?php

function is_valid_zehut$zehut ) {

/*
This function checks validity of Israeli interim ID number (teudat zehut)

See http://www.halemo.com/info/idcard for more info (in Hebrew).

The script has been thoroughly tested. However,
no warranties is given that it ever works.

The script is distributed under GPL v2.

****

Parameter: $zehut - 9 digits.

Use "012345674" to check.

Returns: true if number is correct, false otherwise

Tested under 4.3.2. Requires PHP 3.0.9

Author: Oleg Sverdlov <info@ols.co.il>
OLS Software http://www.ols.co.il

*/

    
function add10$num ) {
        
// handles max 999
        
$d100 floor($num/100);
        
$num $num-($d100*100);
        
$d10 floor($num/10);
        
$num $num-($d10*10);

        return 
$d100 $d10 $num;
    };

    if( 
strlen($zehut) > ) {
        return 
false;
    }

    
$arrZehut = array();

    if( 
preg_match'/(d)(d)(d)(d)(d)(d)(d)(d)(d)/'$zehut$arrZehut ) == ) {
        
// Do not match
        
return false;
    }


    
$pos 1;
    
$s 0;
    for( 
$i=1$i<=9$i++ ) {
        
$s += add10$arrZehut[$i] * $pos );
        
$pos 3-$pos// pos is 1-2-1-2-1-2-1-2-1
    
}

    return (( 
$s 10 ) == );
// end of is_valid_zehut()

?>


Usage Example




Rate This Script





Search



This Category All Categories