Validate International Securities Identification Number: Difference between revisions

no edit summary
(sql pl)
No edit summary
Line 2,385:
IsinCheckDigit = (10 - (total Mod 10)) Mod 10
End Function
</lang>
 
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<lang Yabasic>sub luhntest(cardnr$)
local i, j, s1, s2, l
cardnr$ = Trim$(cardnr$) // remove spaces
l = Len(cardnr$)
// sum odd numbers
For i = l To 1 Step -2
s1 = s1 + (asc(mid$(cardnr$, i, 1)) - Asc("0"))
Next
// sum even numbers
For i = l-1 To 1 Step -2
j = asc(mid$(cardnr$, i, 1)) - Asc("0")
j = j * 2
If j > 9 j = mod(j, 10) + 1
s2 = s2 + j
Next
return mod(s1 + s2, 10) = 0
End sub
// ------=< MAIN >=-----
data "US0378331005", "US0373831005", "U50378331005", "US03378331005", "AU0000XVGZA3", "AU0000VXGZA3", "FR0000988040", ""
do
read test_item$
if test_item$ = "" break
l = Len(test_item$)
If l <> 12 Then
Print test_item$, " Invalid, length <> 12 char."
Continue
End If
c1$ = mid$(test_item$, 1, 1) : c2$ = mid$(test_item$, 2, 1)
If c1$ < "A" Or c1$ > "Z" or c2$ < "A" or c2$ > "Z" Then
Print test_item$, " Invalid, number needs to start with 2 characters"
Continue
End If
test_str$ = ""
For n = 1 To l
x = asc(mid$(test_item$, n, 1)) - Asc("0")
// if is a letter we to correct for that
If x > 9 x = x - 7
If x < 10 Then
test_str$ = test_str$ + Str$(x)
Else // two digest number
test_str$ = test_str$ + Str$(int(x / 10)) + Str$(mod(x, 10))
End If
Next
Print test_item$;
if luhntest(test_str$) then print " Valid" else print " Invalid, checksum error" end if
loop
</lang>
 
672

edits