Validate International Securities Identification Number: Difference between revisions
Validate International Securities Identification Number (view source)
Revision as of 11:15, 20 May 2024
, 1 month ago→{{header|REXX}}: improved and made ooRexx compatible
Langurmonkey (talk | contribs) |
Walterpachl (talk | contribs) (→{{header|REXX}}: improved and made ooRexx compatible) |
||
Line 2,702:
=={{header|REXX}}==
<syntaxhighlight lang="rexx"></
if z='' then z= "US0378331005 US0373831005 U50378331005 US03378331005 AU0000XVGZA3" ,▼
If z='' Then
/* [↓] process all specified ISINs.*/▼
'US037*331005',
'XY037833100Z AU0000XVGZA3 AU0000VXGZA3 FR0000988040'
$= /* [↓] construct list of ISIN digits. */▼
valid='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' /*X must contain 0-->9 A-->Z */
x=word(z,n)
p=verify(x,valid,'N')
If p>0 Then msg='invalid character in position' p':' substr(x,p,1)
Else Do
@= /*placeholder for the "not" in message.*/▼
dd=''
Do k=1 To length(x)
End
end /*n*/ /* [↑] 1st 3 IFs could've been combined*/▼
msg=''
▲exit /*stick a fork in it, we're all done. */
Select
When length(x)\==12 Then msg='not exactly 12 chars'
When \datatype(right(x,1),'W') Then msg='last character is not a digit'
Otherwise
$= $ + substr(y, j, 1) + left(_, 1) + substr(_, 2 , 1, 0)▼
If \luhn(dd) Then msg='does
End
return right($, 1)==0 /*return "1" if number passed Luhn test*/</syntaxhighlight>▼
End
If msg='' Then
Say right(x,15) ' valid' /* display the positive message. */
Else
Say right(x,15) 'not valid:' msg /* display the problem */
End /*n*/
/*-----------------------------------------------------------------------------------*/
luhn: Procedure
y=reverse(left(0,length(x)//2)x) /* add leading zero If needed & reverse */
Do j=1 To length(y)-1 By 2
_=2*substr(y,j+1,1)
End
▲
{{out|output|text= when using the default inputs:}}
<pre>
US0373831005 not valid: does not pass the Luhn test
U50378331005 not valid: not starting with 2 capital chars
US03378331005 not valid: not exactly 12 chars
US037*331005 not valid: invalid character in position 6: *
XY037833100Z not valid: last character is not a digit
AU0000VXGZA3 valid▼
FR0000988040 valid
</pre>
|