Programming/PowerBuilder

사업자번호 유효성체크

초록깨비 2021. 4. 23. 10:08
728x90

 [ 파워빌더에서 사업자번호 유효성 체크 하는 방법]

 

 

 

integer li_Sum = 0 , li_Save = 0

 

// Null Check

if isNull(sId) then Return -1

 

// 자리수 chk : 10자리 , 12자리('-' 포함)

if Not ( ( Len(sId) = 12 ) or ( Len(sId) = 10 ) ) then Return -1

 

// '-' 제거

if Len(sId) = 12 then

 

  sId = Left(sId,3) + Mid(sId,5,2) + Right(sId,5)

 

end if

 

// 숫자 이외의 문자 Check

if Not IsNumber(sId) then Return -1

 

// 합계

li_Sum =  ( Integer(Mid(sId, 1, 1)) * 1 )    + &

             ( Integer(Mid(sId, 2, 1)) * 3 )    + &

             ( Integer(Mid(sId, 3, 1)) * 7 )    + &

             ( Integer(Mid(sId, 4, 1)) * 1 )    + &

             ( Integer(Mid(sId, 5, 1)) * 3 )    + &

             ( Integer(Mid(sId, 6, 1)) * 7 )    + &

             ( Integer(Mid(sId, 7, 1)) * 1 )    + &

             ( Integer(Mid(sId, 8, 1)) * 3 ) 

 

 

// 합계의 단단위

li_Save = Mod(li_Sum, 10)

 

// 9번째 결과의 10단위

li_Save += Integer((Integer(Mid(sId,9,1)) * 5) / 10)

 

// 9번째 결과의 단단위

li_Save += Mod(Integer(Mid(sId,9,1)) * 5, 10)

 

// 결과의 단단위

if li_Save > 10 then  li_Save = Mod(li_Save, 10)

 

 

 

li_Save = Mod(10 - li_Save, 10)

 

// Check Digit 과 비교

if li_Save = Integer(Mid(sId,10,1)) then  Return 1  else     Return -1

 

 

 

728x90