diff --git a/web/public/locales/en/views/faceLibrary.json b/web/public/locales/en/views/faceLibrary.json index 2dbb1a4fd..354049156 100644 --- a/web/public/locales/en/views/faceLibrary.json +++ b/web/public/locales/en/views/faceLibrary.json @@ -2,7 +2,8 @@ "description": { "addFace": "Add a new collection to the Face Library by uploading your first image.", "placeholder": "Enter a name for this collection", - "invalidName": "Invalid name. Names can only include letters, numbers, spaces, apostrophes, underscores, and hyphens." + "invalidName": "Invalid name. Names can only include letters, numbers, spaces, apostrophes, underscores, and hyphens.", + "nameCannotContainHash": "Name cannot contain #." }, "details": { "timestamp": "Timestamp", diff --git a/web/src/components/input/TextEntry.tsx b/web/src/components/input/TextEntry.tsx index e266444c7..4abf942ac 100644 --- a/web/src/components/input/TextEntry.tsx +++ b/web/src/components/input/TextEntry.tsx @@ -20,6 +20,8 @@ type TextEntryProps = { children?: React.ReactNode; regexPattern?: RegExp; regexErrorMessage?: string; + forbiddenPattern?: RegExp; + forbiddenErrorMessage?: string; }; export default function TextEntry({ @@ -30,11 +32,16 @@ export default function TextEntry({ children, regexPattern, regexErrorMessage = "Input does not match the required format", + forbiddenPattern, + forbiddenErrorMessage = "Input contains invalid characters", }: TextEntryProps) { const formSchema = z.object({ text: z .string() .optional() + .refine((val) => !val || !forbiddenPattern?.test(val), { + message: forbiddenErrorMessage, + }) .refine( (val) => { if (!allowEmpty && !val) return false; diff --git a/web/src/components/overlay/detail/FaceCreateWizardDialog.tsx b/web/src/components/overlay/detail/FaceCreateWizardDialog.tsx index 6436ef040..86eae6acb 100644 --- a/web/src/components/overlay/detail/FaceCreateWizardDialog.tsx +++ b/web/src/components/overlay/detail/FaceCreateWizardDialog.tsx @@ -128,6 +128,8 @@ export default function CreateFaceWizardDialog({ }} regexPattern={/^[\p{L}\p{N}\s'_-]{1,50}$/u} regexErrorMessage={t("description.invalidName")} + forbiddenPattern={/#/} + forbiddenErrorMessage={t("description.nameCannotContainHash")} >