We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2112618 commit c775711Copy full SHA for c775711
src/lib/string.spec.ts
@@ -124,14 +124,13 @@ describe("string tests", () => {
124
test.each([
125
[null as unknown as string, false],
126
[undefined as unknown as string, false],
127
- ["7569217076985", true],
128
["7561234567891", false],
+ ["7569217076985", true],
129
["756.9217.0769.85", true],
130
- ["test756.9217.0769.85", false],
+ ["756..9217.0769.85", false],
131
["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],
+ ["test756.9217.0769.85", false],
+ ["7.56..9217...0769.85", false],
135
])("check if the social insurance number is valid or not", (ahvNumber, expected) => {
136
expect(isValidSwissSocialSecurityNumber(ahvNumber)).toBe(expected);
137
});
src/lib/string.ts
@@ -85,7 +85,7 @@ export function isValidSwissSocialSecurityNumber(socialInsuranceNumber: string):
85
if (!socialInsuranceNumberWithDots.test(socialInsuranceNumber) && !socialInsuranceNumberWithoutDots.test(socialInsuranceNumber)) {
86
return false;
87
}
88
- const compactNumber = socialInsuranceNumber.replaceAll(/[\s.]+/g, "");
+ const compactNumber = socialInsuranceNumber.replaceAll(".", "");
89
const digits = compactNumber.slice(0, -1);
90
const reversedDigits = [...digits].reverse().join("");
91
const reversedDigitsArray = [...reversedDigits];
0 commit comments