diff --git a/src/components/SpruceForm/errors.ts b/src/components/SpruceForm/errors.ts index 5fe0fb00fb..605c2b11ea 100644 --- a/src/components/SpruceForm/errors.ts +++ b/src/components/SpruceForm/errors.ts @@ -55,7 +55,7 @@ export const transformErrors = (errors: AjvError[]) => return { ...error, message: - "Value can only contain numbers, letters, periods and hyphens.", + "Value can only contain numbers, letters and these symbols: -._~().", }; case "noSpaces": return { diff --git a/src/utils/validators/index.ts b/src/utils/validators/index.ts index 9af2a3a581..00ab9e8dc3 100644 --- a/src/utils/validators/index.ts +++ b/src/utils/validators/index.ts @@ -138,7 +138,7 @@ const validateRegexp = (regexp: string): boolean => { * @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 = /^[0-9a-zA-Z-._~()]*$/; return noSpecialCharacters.test(str); }; diff --git a/src/utils/validators/validators.test.ts b/src/utils/validators/validators.test.ts index 4be7ce014d..45ad6277e7 100644 --- a/src/utils/validators/validators.test.ts +++ b/src/utils/validators/validators.test.ts @@ -12,13 +12,13 @@ import { describe("validateNoSpecialCharacters", () => { it("returns true if string has no special characters", () => { expect(validateNoSpecialCharacters("")).toBe(true); - expect(validateNoSpecialCharacters("hello_world")).toBe(true); + expect(validateNoSpecialCharacters("helloworld-_~)(")).toBe(true); expect(validateNoSpecialCharacters("hello-world123")).toBe(true); expect(validateNoSpecialCharacters("helloworld.123")).toBe(true); + expect(validateNoSpecialCharacters("hellowo~rld.123")).toBe(true); expect(validateNoSpecialCharacters("helloWorld123")).toBe(true); expect(validateNoSpecialCharacters(" ")).toBe(false); - expect(validateNoSpecialCharacters("s ")).toBe(false); expect(validateNoSpecialCharacters("he/lloworld")).toBe(false); expect(validateNoSpecialCharacters("hello%world")).toBe(false); });