Created
September 24, 2018 08:14
-
-
Save ibnux/4e99852482903fe350f98039bed2e7a9 to your computer and use it in GitHub Desktop.
Validasi Nomor KTP sederhana dari tanggal lahir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Validasi KTP sederhana | |
function cekKTP($nik,$tanggal,$bulan,$tahun){ | |
if(strlen($nik) != 16){ | |
return false; | |
} | |
$d = substr($nik, 6, 2); | |
$m = substr($nik, 8, 2); | |
$y = substr($nik, 10, 2); | |
//jika tahun full, ambil 2 digit terakhir | |
if(strlen($tahun==4)){ | |
$tahun = substr($tahun,2,2); | |
} | |
if (intval($d) > 40) { | |
//Wanita | |
$d = intval($d) - 40; | |
} | |
if($tanggal/$d != 1){ | |
return false; | |
} | |
if($bulan/$m != 1){ | |
return false; | |
} | |
if($tahun/$y != 1){ | |
return false; | |
} | |
//setelah berhasil melewati rintangan, berarti nomornya valid (tidak 100% valid) | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment