Welcome to the Blog.

Thoughts, updates, and stories.

Welcome to the Blog.

Thoughts, updates, and stories.

Welcome to the Blog.

Thoughts, updates, and stories.

Welcome to the Blog.

Thoughts, updates, and stories.

Welcome to the Blog.

Thoughts, updates, and stories.

import { useForm } from "framer"; import { useEffect } from "react"; export function FormValidator() { const { values, state, setError, setStep, submit } = useForm(); // Regex patterns const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; const phoneRegex = /^\+?[0-9\s\-]{7,15}$/; const validPostcodes = ["10115", "75001", "80331"]; // or fetch from JSON useEffect(() => { if (state === "submit") { const { email, telephone, PLZ } = values; if (!emailRegex.test(email)) { setError("email", "Invalid email"); setStep("error"); return; } if (!phoneRegex.test(telephone)) { setError("phone", "Invalid phone number"); setStep("error"); return; } if (!validPostcodes.includes(PLZ)) { setError("postcode", "Invalid postal code"); setStep("error"); return; } setStep("success"); submit(); // Continue to Zapier } }, [state]); return null; }