Skip to content

Commit d4a9db6

Browse files
committed
Improved regex
1 parent 7e8c67f commit d4a9db6

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/lib/swissStandards.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export function isValidSwissIbanNumber(ibanNumber: string): boolean {
1616

1717
// 2. Define allowed strict formats
1818
// - with spaces: "CHXX XXXX XXXX XXXX XXXX X"
19-
const compactIbanNumberWithWhiteSpaces = new RegExp(/^CH\d{2}(?:\s[A-Z0-9]{4}){4}\s[A-Z0-9]{1}$/);
19+
const compactIbanNumberWithWhiteSpaces = new RegExp(/^CH[0-9]{2} [0-9]{4} [0-9][A-Z0-9]{3} [A-Z0-9]{4} [A-Z0-9]{4} [A-Z0-9]$/);
2020
// - without spaces: "CHXXXXXXXXXXXXXXXXXXX"
21-
const compactIbanNumberWithoutWhiteSpaces = new RegExp(/^CH\d{2}[A-Z0-9]{17}$/);
21+
const compactIbanNumberWithoutWhiteSpaces = new RegExp(/^CH[0-9]{7}[A-Z0-9]{12}$/);
2222

2323
// 3. Check if the input matches one of the allowed formats
2424
if (!(compactIbanNumberWithWhiteSpaces.test(ibanNumber) || compactIbanNumberWithoutWhiteSpaces.test(ibanNumber))) {

0 commit comments

Comments
 (0)