Validate International Securities Identification Number: Difference between revisions

Content added Content deleted
(→‎{{header|Tcl}}: add Transact-SQL)
(→‎{{header|J}}: Update for new test cases)
Line 889: Line 889:
=={{header|J}}==
=={{header|J}}==


'''Solution:'''
{{update|J|Use the new test-cases, and consider calling the existing Luhn algorithm implementation from the ''[[Luhn test of credit card numbers]]'' task instead of duplicating it.}}
<lang j>require'regex'
validFmt=: 0 -: '^[A-Z]{2}[A-Z0-9]{9}[0-9]{1}$'&rxindex


<lang j>splt=: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' i. ' ' -.~ ":
df36=: ;@([: <@":"0 '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'&i.) NB. decimal from base 36
luhn=: 0 = 10 (| +/@,) 10 #.inv 1 2 *&|: _2 "."0\ |. NB. as per task Luhn_test_of_credit_card_numbers#J
checksum=: 3 : '10| - +/ splt (* 2 1 $~ #) |. splt splt y'


validISIN=: validFmt *. luhn@df36</lang>
assert 5 = checksum 'US037833100'

assert 0 = checksum 'US037833107'
'''Required Examples:'''
assert 3 = checksum 'AU0000VXGZA'
<lang j> Tests=: 'US0378331005';'US0373831005';'U50378331005';'US03378331005';'AU0000XVGZA3';'AU0000VXGZA3';'FR0000988040'
assert 6 = checksum 'GB000263494'</lang>
validISIN&> Tests
1 0 0 0 1 1 1</lang>


=={{header|Java}}==
=={{header|Java}}==