IBAN: Difference between revisions

13 bytes removed ,  11 years ago
Line 292:
 
=={{header|Perl 6}}==
<lang perl6>for ('GB82 WEST 1234 5698 7654 32',
'GB82 WEST 1234 5698 7654 32',
'gb82 west 1234 5698 7654 32',
'GB82 TEST 1234 5698 7654 32'
{
) {
printfsay "%s$_ is %svalid.\n",{ $_,'in' x !is_valid_iban($_) ?? '' !! 'NOT '}valid";
}
 
 
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 ]>/;
 
returnmy 0$country if= $iban ~~ m/<-[.substr(0,2)..9A..Za..z]>/uc;
return 0False unless %len.exists({$country)} and $iban.chars == %len{$country};
 
my $country = $iban.uc.substr(0,2);
 
return 0 unless %len.exists($country) and $iban.chars == %len{$country};
 
$iban ~~ s/(.**4)(.+)/$1$0/;
return $iban.subst(:g, /(\D)/, ->{ $/ {:36("~$0"_) }) % 97 == 1;
 
$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 NOT validinvalid.
</pre>
 
Anonymous user