IBAN: Difference between revisions

41 bytes removed ,  10 years ago
→‎{{header|Perl 6}}: proposing a more idiomatic version (using a subset of Str)
No edit summary
(→‎{{header|Perl 6}}: proposing a more idiomatic version (using a subset of Str))
Line 461:
 
=={{header|Perl 6}}==
<lang perl6>forsubset 'GB82IBAN WESTof 1234Str 5698where 7654sub 32',($_ is copy) {
'gb82 west 1234 5698 7654 32',
'GB82 TEST 1234 5698 7654 32'
say "$_ is { 'in' x !is_valid_iban($_) }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 478 ⟶ 470:
RS 22 SA 24 SE 24 SI 19 SK 24 SM 27 TN 24 TR 26 VG 24
>;
$iban ~~ s:g/\s//;
return False if $iban ~~ m/<-[ 0..9 A..Z a..z ]>/;
my $country = $iban.substr(0,2).uc;
return False unless %len{$country} and $iban.chars == %len{$country};
$iban ~~ s/(.**4)(.+)/$1$0/;
return $iban.subst(:g, /\D/, { :36(~$_) }) % 97 == 1;
 
for 'GB82 WEST 1234 5698 7654 32',
$iban ~~ s:g/\s//;
'gb82 west 1234 5698 7654 32',
return False if $iban ~~ m/<-[ 0..9 A..Z a..z ]>/;
'GB82 TEST 1234 5698 7654 32'
 
my $country = $iban.substr(0,2).uc;
say "$_ is { $_ ~~ IBAN ?? 'valid' !! 'invalid' }";
return False unless %len{$country} and $iban.chars == %len{$country};
 
$iban ~~ s/(.**4)(.+)/$1$0/;
return $iban.subst(:g, /\D/, { :36(~$_) }) % 97 == 1;
}</lang>
{{out}}
1,934

edits