Anonymous user
Validate International Securities Identification Number: Difference between revisions
Validate International Securities Identification Number (view source)
Revision as of 21:47, 2 March 2019
, 5 years ago→{{header|Visual Basic}}
SqrtNegInf (talk | contribs) m (→{{header|Perl 6}}: 'bare' regex no longer allowed with ternary) |
|||
Line 2,314:
=={{header|Visual Basic}}==
{{works with|Visual Basic|VB6 Standard}}
Calls LuhnCheckPassed() function described at [[Luhn_test_of_credit_card_numbers#Visual_Basic]]
<lang vb>Function IsValidISIN(ByVal ISIN As String) As Boolean
Dim s As String, c As String
Dim i As Long
If Len(ISIN) = 12 Then
For i = 1 To Len(ISIN)
c = UCase$(Mid(ISIN, i, 1))
Select Case c
Case "A" To "Z"
If i = 12 Then Exit Function
s = s & CStr(Asc(c) - 55)
If i < 3 Then Exit Function
s = s & c
Case Else
Exit Function
End Select
Next i
IsValidISIN = LuhnCheckPassed(s)
End If
End Function</lang>
Test:
<lang vb>Sub Main()
Debug.Assert IsValidISIN("US0378331005")
Debug.Assert Not IsValidISIN("US0373831005")
Debug.Assert Not IsValidISIN("U50378331005")
Debug.Assert Not IsValidISIN("US03378331005")
Debug.Assert IsValidISIN("AU0000XVGZA3")
Debug.Assert IsValidISIN("AU0000VXGZA3")
Debug.Assert IsValidISIN("FR0000988040")
Debug.Assert Not IsValidISIN("FR000098804O")
End Sub</lang>
=={{header|Yabasic}}==
|