Skip to content

Commit 0eea535

Browse files
committed
Fixes
1 parent 7bbf360 commit 0eea535

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

lib/src/utils/validators.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,7 @@ bool isValidIban(String iban) {
438438
String rearranged = iban.substring(4) + iban.substring(0, 4);
439439
String numericIban = rearranged.split('').map((char) {
440440
int charCode = char.codeUnitAt(0);
441-
if (charCode >= 65 && charCode <= 90) {
442-
return (charCode - 55).toString(); // A=10, B=11, ..., Z=35
443-
} else {
444-
return char;
445-
}
441+
return charCode >= 65 && charCode <= 90 ? (charCode - 55).toString() : char;
446442
}).join();
447443

448444
int remainder = int.parse(numericIban.substring(0, 9)) % 97;

test/form_builder_validators_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,4 +1108,25 @@ void main() {
11081108
expect(validator(null), isNull); // Log message will be displayed
11091109
}),
11101110
);
1111+
1112+
testWidgets(
1113+
'FormBuilderValidators.iban',
1114+
(WidgetTester tester) => testValidations(tester, (context) {
1115+
final validator = FormBuilderValidators.iban();
1116+
// Pass
1117+
expect(validator('GB82WEST12345698765432'), isNull); // A valid UK IBAN
1118+
expect(
1119+
validator('DE89370400440532013000'), isNull); // A valid German IBAN
1120+
expect(validator('FR1420041010050500013M02606'),
1121+
isNull); // A valid French IBAN
1122+
expect(validator('GB82 WEST 1234 5698 7654 32'),
1123+
isNull); // Format with spaces
1124+
1125+
// Fail
1126+
//expect(validator(''), isNotNull); // Empty string
1127+
expect(validator('INVALIDIBAN'), isNotNull); // Invalid IBAN
1128+
expect(validator('GB82WEST1234569876543212345'), isNotNull); // Too long
1129+
expect(validator('GB82WEST1234'), isNotNull); // Too short
1130+
}),
1131+
);
11111132
}

0 commit comments

Comments
 (0)