From c4a1c16b94478cb990d7069ce2c4151f9b8486c0 Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Mon, 21 Oct 2024 11:23:19 +0100 Subject: [PATCH] fix(frontend): regex input control --- .../form/inputs/triggers/PatternInput.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/frontend/src/components/visual-editor/form/inputs/triggers/PatternInput.tsx b/frontend/src/components/visual-editor/form/inputs/triggers/PatternInput.tsx index 5ef217ae..3ca4a156 100644 --- a/frontend/src/components/visual-editor/form/inputs/triggers/PatternInput.tsx +++ b/frontend/src/components/visual-editor/form/inputs/triggers/PatternInput.tsx @@ -266,9 +266,16 @@ const PatternInput: FC = ({ {typeof value === "string" && patternType === "regex" ? ( - (value.trim() !== "" && value !== "/") ?? - t("message.regex_is_invalid"), + validate: (pattern) => { + try { + if (typeof pattern === "string") + new RegExp(pattern.slice(1, -1)); + + return true; + } catch (_e) { + return t("message.regex_is_invalid"); + } + }, setValueAs: (v) => `/${v}/`, })} label={t("label.regex")}