Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added hasNoIllegalCharacters validator #3206

Merged
merged 1 commit into from Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/validators-util/documentation/validators.mdx
Expand Up @@ -39,3 +39,4 @@ import { isValidRegistreringsnummer } from '@fremtind/jkl-validators-util';
- isValidOrganisasjonsnummer
- isValidName
- hasMinimumWords
- hasNoIllegalCharacters
@@ -0,0 +1,13 @@
import { hasNoIllegalCharacters } from "./hasNoIllegalCharacters";

describe("hasNoIllegalCharacters", () => {
it("should return true if no illegal characters is present", () => {
expect(hasNoIllegalCharacters("Heisann")).toBe(true);
expect(hasNoIllegalCharacters("123-ASD")).toBe(true);
});

it("should return false if illegal characters is present", () => {
expect(hasNoIllegalCharacters("{")).toBe(false);
expect(hasNoIllegalCharacters("123;230")).toBe(false);
});
});
@@ -0,0 +1,4 @@
const ILLEGAL_CHARS_REGEX = /[[\]{}%¤/()$@£€^~*?_;:"]+/;
export const ILLEGAL_CHARS_STRING = '[]{}%¤/()$@£€^~*?_;:"';

export const hasNoIllegalCharacters = (value: string): boolean => !ILLEGAL_CHARS_REGEX.test(value);
1 change: 1 addition & 0 deletions packages/validators-util/src/index.ts
Expand Up @@ -9,3 +9,4 @@ export { isValidFodselsnummer } from "./isValidFodselsnummer/isValidFodselsnumme
export { isValidOrganisasjonsnummer } from "./isValidOrganisasjonsnummer/isValidOrganisasjonsnummer";
export { isValidName } from "./isValidName/isValidName";
export { hasMinimumWords } from "./hasMinimumWords/hasMinimumWords";
export { hasNoIllegalCharacters } from "./hasNoIllegalCharacters/hasNoIllegalCharacters";