In response to my good friend’s post :
http://www.yoman.com.sg/2007/5/29/validates_nric_of
I present to you the same codes written in PHP
$nric = $_GET[nric];
if(is_NRIC($nric))
{echo "Correct NRIC";}
else
{echo "Your NRIC is wrong";}
function is_NRIC($nric)
{
if(strlen($nric)==9)
{
$nric = strtoupper($nric);
$prefix = substr($nric,0,1);
$postfix = substr($nric,8,1);
$ic_number = substr($nric,1,7);
$weight = array(2,7,6,5,4,3,2);
$lookup[S] = array(J,Z,I,H,G,F,E,D,C,B,A);
$lookup[T] = array(G,F,E,D,C,B,A,J,Z,I,H);
$lookup[F] = array(X,W,U,T,R,Q,P,N,M,L,K);
$lookup[G] = array(R,Q,P,N,M,L,K,X,W,U,T);
for($i=0;$weight[$i];$i++)
{
$num+=substr($ic_number,$i,1)*$weight[$i];
}
$num %= 11;
if($lookup[$prefix][$num]==$postfix)
{
return true;
}else
{
return false;
}
}
}
I’ve got several implementations in various languages for this on Github – https://github.com/mjallday/nric-lib
Great! Cheers and thanks for the input!