Skip to content

Commit

Permalink
Input validering regex: Enda løsere validering av fritekst og navn
Browse files Browse the repository at this point in the history
  • Loading branch information
espenwaaga committed Nov 4, 2024
1 parent fb4d73f commit 930231b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions packages/form-validators/src/validatorsHelper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ describe('validatorsHelper', () => {
it('Skal sjekke om input er tekst', () => {
expect(textRegex.test('text')).toBe(true);
expect(textRegex.test('3434')).toBe(true);
expect(textRegex.test('Bokstaver fra andre språk BØR være greit øåÆØÅAaÁáBbCcČčDdĐđEeFfGgHhIiJjKkLlMmNnŊŋOoPpRrSsŠšTtŦŧUuVvZzŽžéôèÉöüäÖÜ')).toBe(true);
expect(
textRegex.test(
'Bokstaver fra andre språk BØR være greit øåÆØÅAaÁáBbCcČčDdĐđEeFfGgHhIiJjKkLlMmNnŊŋOoPpRrSsŠšTtŦŧUuVvZzŽžéôèÉöüäÖÜ',
),
).toBe(true);
});
});

Expand All @@ -62,7 +66,7 @@ describe('validatorsHelper', () => {
it('Skal sjekke om input er et navn', () => {
expect(nameRegex.test('Ola Nordmann')).toBe(true);
expect(nameRegex.test("Jan-Ole O'Brian Jr")).toBe(true);
expect(nameRegex.test('Ola Nordmann!')).toBe(false);
expect(nameRegex.test('<Ola Nordmann>')).toBe(false);
});
});

Expand Down
8 changes: 4 additions & 4 deletions packages/form-validators/src/validatorsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export const integerOptionalNegativeRegex = /^\s*-?\d+\s*$/;
export const decimalRegex = /^\d+(.\d{1,2})?$/;
export const saksnummerOrFodselsnummerPattern = /^\d{0,18}$/;

export const textRegex = /^[\p{N}\p{L}\p{Z}.'\-/%§!?@_()+:;,="&\n]*$/u;
export const textGyldigRegex = /[\p{N}\p{L}\p{Z}.'\-/%§!?@_()+:;,="&\n]*/ug;
export const textRegex = /^[\p{N}\p{L}\p{Z}\p{M}\p{P}\p{Sc}\p{Sk}\n\t+=]*$/u;
export const textGyldigRegex = /[\p{N}\p{L}\p{Z}\p{M}\p{P}\p{Sc}\p{Sk}\n\t+=]*/gu;

export const nameRegex = /^[0-9\p{L}\p{Z}.'-]*$/u;
export const nameGyldigRegex = /[0-9\p{L}\p{Z}.'-]*/ug;
export const nameRegex = /^[\p{N}\p{L}\p{Z}\p{M}.'-]*$/u;
export const nameGyldigRegex = /[\p{N}\p{L}\p{Z}\p{M}.'-]*/gu;

export const isEmpty = (text?: string | number | boolean | moment.Moment | null) =>
text === null || text === undefined || text.toString().trim().length === 0;
Expand Down

0 comments on commit 930231b

Please sign in to comment.