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

Commit

Permalink
allow more symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
SupaJoon committed Oct 12, 2023
1 parent 6b8a907 commit 93719e0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/SpruceForm/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/validators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
4 changes: 2 additions & 2 deletions src/utils/validators/validators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit 93719e0

Please sign in to comment.