Skip to content

Commit c775711

Browse files
committed
Add replace only the dot out of the number
1 parent 2112618 commit c775711

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/lib/string.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,13 @@ describe("string tests", () => {
124124
test.each([
125125
[null as unknown as string, false],
126126
[undefined as unknown as string, false],
127-
["7569217076985", true],
128127
["7561234567891", false],
128+
["7569217076985", true],
129129
["756.9217.0769.85", true],
130-
["test756.9217.0769.85", false],
130+
["756..9217.0769.85", false],
131131
["756.1234.5678.91", false],
132-
["756.1234.5678.91", false],
133-
["7 5......69 2...1707......69.85", false],
134-
["7 5......61 2...3456......7......89 1", false],
132+
["test756.9217.0769.85", false],
133+
["7.56..9217...0769.85", false],
135134
])("check if the social insurance number is valid or not", (ahvNumber, expected) => {
136135
expect(isValidSwissSocialSecurityNumber(ahvNumber)).toBe(expected);
137136
});

src/lib/string.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export function isValidSwissSocialSecurityNumber(socialInsuranceNumber: string):
8585
if (!socialInsuranceNumberWithDots.test(socialInsuranceNumber) && !socialInsuranceNumberWithoutDots.test(socialInsuranceNumber)) {
8686
return false;
8787
}
88-
const compactNumber = socialInsuranceNumber.replaceAll(/[\s.]+/g, "");
88+
const compactNumber = socialInsuranceNumber.replaceAll(".", "");
8989
const digits = compactNumber.slice(0, -1);
9090
const reversedDigits = [...digits].reverse().join("");
9191
const reversedDigitsArray = [...reversedDigits];

0 commit comments

Comments
 (0)