[알고리즘]사업자등록번호 체크

phpschool 의 tip&tech 에 있는 내요입니다..

글쓴이:유희목 [알고리즘]사업자등록번호 체크 조회수:73


유희목



Tip&Tech에 사업자 번호 체크하는 알고리즘이 없네요^^

자바로 하나 있는것 같은데....

구래서 올려드립니다

사업자번호 첫번째는 co_serial_1, 둘째는 co_serial_2, 세번째 자리는
co_serial_3 입니다...
Ex) aaa-bb-ccccc
co_serial_1 = aaa
co_serial_2 = bb
co_serial_3 = ccccc

form 에서 post방식으로 받았을때입니다.^^

중간에 연산하는곳에 substr로 걸러내서 intval로 안정해 줘도 연산이 잘 되네
요^^ 에러나는분은 고쳐서 쓰시던지요~~~^^


function error_msg($message)
{
echo("

");
exit;
}

$co_serial_1 = $HTTP_POST_VARS[co_serial_1];
$co_serial_2 = $HTTP_POST_VARS[co_serial_2];
$co_serial_3 = $HTTP_POST_VARS[co_serial_3];

if (!isset($co_serial_1) || !isset($co_serial_2) || !isset
($co_serial_3))
{
error_msg("사업자등록번호를 입력해 주세요.");
}
elseif (ereg("[^0-9]+",$co_serial_1) || ereg("[^0-9]+",$co_serial_2) ||
ereg("[^0-9]+",$co_serial_3))
{
error_msg("사업자등록번호를 정확히 입력해 주세요.");
}
else
{
$co_serial = $co_serial_1.$co_serial_2.$co_serial_3;
$IDtot = 0;
$IDAdd = "137137135";
for ($i=0;$i < 9 ; $i++)
{
$IDtot = $IDtot + (substr($co_serial,$i,1) * substr($IDAdd,$i,1));
}

$IDtot = $IDtot + ((substr($co_serial,8,1)*5)/10);
$IDtot = 10 - ($IDtot % 10);

if (substr($co_serial_3,-1) != substr($IDtot,-1))
{
error_msg("사업자등록번호를 정확히 입력해 주세요.");
}
}
?>

즐프하세요~~~

Press ESC to close