Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
SupaJoon committed Oct 13, 2023
1 parent 93719e0 commit 045fb5e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/components/SpruceForm/errors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AjvError } from "@rjsf/core";
import { allowedSymbols } from "utils/validators";

export enum Errors {
Invisible = "invisible",
Expand Down Expand Up @@ -54,8 +55,7 @@ export const transformErrors = (errors: AjvError[]) =>
case "noSpecialCharacters":
return {
...error,
message:
"Value can only contain numbers, letters and these symbols: -._~().",
message: `Value can only contain numbers, letters and these symbols: ${allowedSymbols}.`,
};
case "noSpaces":
return {
Expand Down
5 changes: 4 additions & 1 deletion src/utils/validators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,20 @@ const validateRegexp = (regexp: string): boolean => {
}
};

const allowedSymbols = "-._~()";

/**
* `validateNoSpecialCharacters` tests if a provided string contains no special characters
* @param str - The string to test.
* @returns - true if the string has no special characters and false otherwise
*/
const validateNoSpecialCharacters = (str: string): boolean => {
const noSpecialCharacters = /^[0-9a-zA-Z-._~()]*$/;
const noSpecialCharacters = new RegExp(`^[0-9a-zA-Z${allowedSymbols}]*$`);
return noSpecialCharacters.test(str);
};

export {
allowedSymbols,
validateDuration,
validateEmail,
validateJira,
Expand Down

0 comments on commit 045fb5e

Please sign in to comment.