Skip to content

Instantly share code, notes, and snippets.

View didats's full-sized avatar

Didats Triadi didats

View GitHub Profile
@didats
didats / php_civilid.php
Created November 18, 2013 02:00
Civil ID Validation for Kuwait Citizen using PHP
function validate_civilid($str) {
$valid = false;
if(preg_match("/[0-9]/{12}", $str)) {
$test = ((substr($str, 0, 1) * 2) + ((substr($str, 1, 1) * 1) + ((substr($str, 2, 1) * 6) + ((substr($str, 3, 1) * 3) + ((substr($str, 4, 1) * 7) + ((substr($str, 5, 1) * 9) + ((substr($str, 6, 1) * 10) + ((substr($str, 7, 1) * 5) + ((substr($str, 8, 1) * 8) + ((substr($str, 9, 1) * 4) + ((substr($str, 10, 1) * 2) ) % 11;
if($test == substr($str, 11, 1)) $valid = true;
}
return $valid;
@didats
didats / civil_id_objectivc.m
Last active December 4, 2018 15:57
Civil ID Validation for Kuwait Citizen in Objective C
-(BOOL) validateCivilID:(NSString *)civilID {
bool valid = false;
NSString *regex = @"[0-9]{12}";
NSPredicate *test = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if ([test evaluateWithObject:civilID]) {
double test = 11 - (([[civilID substringWithRange:NSMakeRange(0, 1)] integerValue] * 2) +
([[civilID substringWithRange:NSMakeRange(1, 1)] integerValue] * 1) +