Skip to content

Commit

Permalink
Merge pull request #252 from Hexastack/fix/form-block-trigger-regex-c…
Browse files Browse the repository at this point in the history
…heck-format

fix(frontend): regex input control
  • Loading branch information
marrouchi authored Oct 21, 2024
2 parents af22a6b + e683a83 commit b2c32fe
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,20 @@ const PatternInput: FC<PatternInputProps> = ({
{typeof value === "string" && patternType === "regex" ? (
<RegexInput
{...registerInput(t("message.regex_is_invalid"), idx, {
validate: (value) =>
(value.trim() !== "" && value !== "/") ??
t("message.regex_is_invalid"),
validate: (pattern) => {
try {
if (
pattern.at(0) === "/" &&
pattern.at(-1) === "/" &&
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")}
Expand Down

0 comments on commit b2c32fe

Please sign in to comment.