From 930231b6e02176b0ab6d0f81104983022cdd5440 Mon Sep 17 00:00:00 2001 From: espenwaaga Date: Mon, 4 Nov 2024 11:02:44 +0100 Subject: [PATCH] =?UTF-8?q?Input=20validering=20regex:=20Enda=20l=C3=B8ser?= =?UTF-8?q?e=20validering=20av=20fritekst=20og=20navn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/form-validators/src/validatorsHelper.spec.ts | 8 ++++++-- packages/form-validators/src/validatorsHelper.ts | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/form-validators/src/validatorsHelper.spec.ts b/packages/form-validators/src/validatorsHelper.spec.ts index 68e7b5640a..55e7f549f5 100644 --- a/packages/form-validators/src/validatorsHelper.spec.ts +++ b/packages/form-validators/src/validatorsHelper.spec.ts @@ -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); }); }); @@ -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('')).toBe(false); }); }); diff --git a/packages/form-validators/src/validatorsHelper.ts b/packages/form-validators/src/validatorsHelper.ts index 039f7e12c3..00928c8cee 100644 --- a/packages/form-validators/src/validatorsHelper.ts +++ b/packages/form-validators/src/validatorsHelper.ts @@ -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;