Anonymous user
IBAN: Difference between revisions
→{{header|Perl 6}}: style
(→{{header|Perl 6}}: style) |
|||
Line 292:
=={{header|Perl 6}}==
<lang perl6>for
'gb82 west 1234 5698 7654 32',
'GB82 TEST 1234 5698 7654 32'
{
}
sub is_valid_iban (Str $iban is copy --> Bool) {
my %len = <
AD 24 AE 23 AL 28 AT 20 AZ 28 BA 20 BE 16 BG 22 BH 22 BR 29 CH 21
Line 312 ⟶ 311:
$iban ~~ s:g/\s//;
return False if $iban ~~ m/<-[ 0..9 A..Z a..z ]>/;
▲ return 0 unless %len.exists($country) and $iban.chars == %len{$country};
$iban ~~ s/(.**4)(.+)/$1$0/;
▲ $iban.subst(:g, /(\D)/, -> $/ {:36("$0")}) % 97 == 1;
}</lang>
{{out}}
<pre>
GB82 WEST 1234 5698 7654 32 is valid.
gb82 west 1234 5698 7654 32 is valid.
GB82 TEST 1234 5698 7654 32 is
</pre>
|