Skip to content

Commit b03a93a

Browse files
committed
Fixed the regex test check
1 parent 2e8fe83 commit b03a93a

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/lib/swissStandards.spec.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,20 @@ describe("Swiss standards test", () => {
1111
["CH93 0000 0000 0000 0000 1", false],
1212
["ch93 0076 2011 6238 5295 7", false],
1313
["DE93 0076 2011 6238 5295 7", false],
14-
])("check if this swiss IBAN is valid or not", (iBanNumberToCheck, expected) => {
14+
])("check if the swiss IBAN number is valid or not", (iBanNumberToCheck, expected) => {
1515
expect(isValidSwissIbanNumber(iBanNumberToCheck)).toBe(expected);
1616
});
1717

1818
test.each([
1919
[null as unknown as string, false],
2020
[undefined as unknown as string, false],
21-
["CH35 0023 0230 1234 5601 X", true],
22-
])("check if this siwss IBAN with letters is valid or not", (iBanNumberToCheck, expected) => {
21+
["CH3400762ABC123DEF456", true],
22+
["CH34 0076 2ABC 123D EF45 6", true],
23+
["Some random string", false],
24+
["DE34 0076 2ABC 123D EF45 3", false],
25+
["CH34 0076 2ABC 123D EF45 \n6", false],
26+
["CH34 0076 2ABC 123D EF45 !", false],
27+
])("check if the siwss IBAN number with letters is valid or not", (iBanNumberToCheck, expected) => {
2328
expect(isValidSwissIbanNumber(iBanNumberToCheck)).toBe(expected);
2429
});
2530

src/lib/swissStandards.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export function isValidSwissIbanNumber(ibanNumber: string): boolean {
2020
// - without spaces: "CHXXXXXXXXXXXXXXXXXXX"
2121
const compactIbanNumberWithoutWhiteSpaces = new RegExp(/^CH\d{2}[A-Z0-9]{17}$/);
2222

23-
// 3. Check if input matches one of the allowed formats
24-
if (!compactIbanNumberWithWhiteSpaces.test(ibanNumber) && !compactIbanNumberWithoutWhiteSpaces.test(ibanNumber)) {
23+
// 3. Check if the input matches one of the allowed formats
24+
if (!(compactIbanNumberWithWhiteSpaces.test(ibanNumber) || compactIbanNumberWithoutWhiteSpaces.test(ibanNumber))) {
2525
return false;
2626
}
2727

@@ -46,7 +46,7 @@ export function isValidSwissIbanNumber(ibanNumber: string): boolean {
4646
}
4747

4848
/**
49-
* Validation of social insurance number with checking the checksum
49+
* Validation of a social insurance number with checking the checksum
5050
* Validation according to https://www.sozialversicherungsnummer.ch/aufbau-neu.htm
5151
* @param socialInsuranceNumber The social insurance number to check
5252
* Must be in one of the following formats:
@@ -55,13 +55,13 @@ export function isValidSwissIbanNumber(ibanNumber: string): boolean {
5555
* @returns The result if the social insurance number is valid or not
5656
*/
5757
export function isValidSwissSocialInsuranceNumber(socialInsuranceNumber: string): boolean {
58-
// 1. Check if input is empty or only whitespace
58+
// 1. Check if the input is empty or only a whitespace
5959
if (isNullOrWhitespace(socialInsuranceNumber)) {
6060
return false;
6161
}
6262

6363
/**
64-
* 2. Check if input matches accepted formats:
64+
* 2. Check if the input matches one of the accepted formats:
6565
* - With dots: 756.XXXX.XXXX.XX
6666
* - Without dots: 756XXXXXXXXXX
6767
*/

0 commit comments

Comments
 (0)