Php > Algorithms
This algorithem checks if an Israeli ID (9 digits) number is valid
This algorithem checks if an Israeli ID (9 digits) number is valid The algorithem (MOD 10) is based on Error Brett code from example 74. The algorithem might work on various ID's cause MOD 10 is the basis of many ID checksums. Add a comment to this example if this algorithem works for you too. // takes a string and returns an array of characters function toCharArray($input){ $len = strlen($input); for ($j=0;$j<$len;$j++){ $char[$j] = substr($input, $j, 1); } return ($char); } function validateID($ID){ //Clean spaces $ID = ereg_replace('[-[:space:]]', '',$ID); //Grab the test digit $Bikoret=substr($ID,8,1); //Take only 8 left digits of the Id. $ID = substr($ID,0,strlen($ID)-1); $dig = toCharArray($ID); $numdig = sizeof($dig); $j = 0; for($i=($numdig-1) ; $i>=0 ; $i-=2){ $dbl[$j] = $dig[$i] * 2; $j++; } $dblsz = sizeof($dbl); $validate = 0; //Sum all the 2x for($i=0 ; $i<$dblsz ; $i++){ $add = toCharArray($dbl[$i]); for($j=0 ; $j
=0; $i-=2){ $validate += $dig[$i]; } If($validate % 10 != 0) { $Bikoret1=(substr($validate, 0, 1) + 1) * 10; } Else { $Bikoret1=$validate; } If($Bikoret1 - $validate == $Bikoret) return 1; else return 0; } ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage