Validate International Securities Identification Number: Difference between revisions
Content added Content deleted
Langurmonkey (talk | contribs) |
Walterpachl (talk | contribs) (→{{header|REXX}}: improved and made ooRexx compatible) |
||
Line 2,702: | Line 2,702: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<syntaxhighlight lang="rexx">/ |
<syntaxhighlight lang="rexx"></syntaxhighlight> |
||
/*REXX program validates International Securities ID numbers. */ |
|||
⚫ | |||
⚫ | |||
If z='' Then /* [?] use the default list of ISINs */ |
|||
⚫ | |||
⚫ | |||
'US037*331005', |
|||
do n=1 for words(z); x=word(z, n); y= x /*obtain an ISIN from the Z list. */ |
|||
'XY037833100Z AU0000XVGZA3 AU0000VXGZA3 FR0000988040' |
|||
⚫ | |||
valid='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' /*X must contain 0-->9 A-->Z */ |
|||
do k=1 for length(x); _= substr(x,k,1) /*the ISIN may contain alphabetic chars*/ |
|||
⚫ | |||
p= pos(_, 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ) /*X must contain A──►Z, 0──►9.*/ |
|||
x=word(z,n) /*obtain an ISIN from the Z list. */ |
|||
p=verify(x,valid,'N') |
|||
else $= $ || p-1 /*convert X string (base 36 ──► dec).*/ |
|||
If p>0 Then msg='invalid character in position' p':' substr(x,p,1) |
|||
end /*k*/ /* [↑] convert alphabetic ──► digits.*/ |
|||
Else Do |
|||
⚫ | |||
dd='' /* [?] construct list of ISIN digits. */ |
|||
Do k=1 To length(x) |
|||
if \datatype( left(x,2),'U') then @= "not" /* " " " " 1st 2 chars cap. let.*/ |
|||
_=substr(x,k,1) /*the ISIN may contain alphabetic chars*/ |
|||
p=pos(_,valid) /*X contains 0-->9 A-->Z */ |
|||
dd=dd||p-1 /*convert X string (base 36 --? dec).*/ |
|||
End |
|||
⚫ | |||
msg='' |
|||
⚫ | |||
Select |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
|||
When length(x)\==12 Then msg='not exactly 12 chars' |
|||
Luhn: procedure; parse arg x; $= 0 /*get credit card number; zero $ sum. */ |
|||
When \datatype( left(x,2),'U') Then msg='not starting with 2 capital chars' |
|||
When \datatype(right(x,1),'W') Then msg='last character is not a digit' |
|||
do j=1 to length(y)-1 by 2; _= 2 * substr(y, j+1, 1) |
|||
Otherwise |
|||
⚫ | |||
If \luhn(dd) Then msg='does not pass the Luhn test' |
|||
End |
|||
⚫ | |||
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:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
US0378331005 valid |
|||
US0373831005 not valid: does not pass the Luhn test |
|||
US0373831005 not valid |
|||
U50378331005 not valid: not starting with 2 capital chars |
|||
U50378331005 not valid |
|||
US03378331005 not valid: not exactly 12 chars |
|||
US03378331005 not valid |
|||
US037*331005 not valid: invalid character in position 6: * |
|||
AU0000XVGZA3 valid |
|||
XY037833100Z not valid: last character is not a digit |
|||
⚫ | |||
AU0000XVGZA3 valid |
|||
⚫ | |||
FR0000988040 valid |
|||
</pre> |
</pre> |
||