diff --git a/web/src/components/inputs/input.tsx b/web/src/components/inputs/input.tsx index 367022e..df2de47 100644 --- a/web/src/components/inputs/input.tsx +++ b/web/src/components/inputs/input.tsx @@ -1,8 +1,9 @@ -import { Field, FieldProps } from "formik"; +import { Field, FieldProps, useFormikContext } from "formik"; import { classNames } from "../../utils"; import { EyeIcon, EyeSlashIcon, CheckCircleIcon, XCircleIcon } from "@heroicons/react/24/solid"; import { useToggle } from "../../hooks/hooks"; import { CustomTooltip } from "../tooltips/CustomTooltip"; +import { useEffect } from "react"; type COL_WIDTHS = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12; @@ -100,16 +101,52 @@ export const RegexField = ({ tooltip, disabled }: RegexFieldProps) => { - const golangRegex = /^((\\\*|\\\?|\\[^\s\\])+|\(\?i\))(\|((\\\*|\\\?|\\[^\s\\])+|\(\?i\)))*$/; - const validRegex = (pattern: string) => { + + // Check for unsupported lookahead and lookbehind assertions + if (/\(\?<=|\(\?/.test(pattern)) { + return false; + } + + // Check for unsupported recursive patterns + if (/\(\?(R|0)\)/.test(pattern)) { + return false; + } + + // Check for unsupported possessive quantifiers + if (/[*+?]{1}\+|\{[0-9]+,[0-9]*\}\+/.test(pattern)) { + return false; + } + + // Check for unsupported control verbs + if (/\\g { let error = ""; @@ -121,6 +158,13 @@ export const RegexField = ({ return error; }; + const { validateForm } = useFormikContext(); + useEffect(() => { + if (useRegex) { + validateForm(); + } + }, [useRegex]); + return (