# Contact Form

> Contact form validation with name, email, subject, message, and optional phone (E.164).

- Name: `contact-form`
- Categories: forms
- Detail page: https://open-types.dev/types/contact-form

## Install

```bash
# Types only
npx shadcn add @open-types/contact-form

# Types + Zod v4 validators
npx shadcn add @open-types/contact-form-zod

# Types + real-world examples
npx shadcn add @open-types/contact-form-examples
```

## Types

```typescript
export interface ContactForm {
  name: string;
  email: string;
  subject: string;
  message: string;
  phone?: string;
}
```

## Zod validator

```typescript
import * as z from "zod";
import type { ContactForm } from "../types/contact-form";

const E164_REGEX = /^\+[1-9]\d{1,14}$/;

export const contactFormSchema = z.object({
  name: z.string().min(1, { error: "Name is required" }),
  email: z.email({ error: "Invalid email address" }),
  subject: z.string().min(1, { error: "Subject is required" }),
  message: z
    .string()
    .min(10, { error: "Message must be at least 10 characters" })
    .max(5000, { error: "Message must be at most 5000 characters" }),
  phone: z
    .string()
    .regex(E164_REGEX, { error: "Phone must be in E.164 format (e.g. +14155551234)" })
    .optional(),
}) satisfies z.ZodType<ContactForm>;

export type { ContactForm } from "../types/contact-form";
```

## Examples

```typescript
// Source: hand-crafted
import type { ContactForm } from "../types/contact-form";

export const contactFormExamples = {
  minimal: {
    name: "Jenny Rosen",
    email: "jenny@example.com",
    subject: "Question about pricing",
    message: "Could you share an enterprise quote for 50 seats?",
  } satisfies ContactForm,
  withPhone: {
    name: "Alex Patel",
    email: "alex@example.com",
    subject: "Demo request",
    message: "Looking for a 30-minute demo next week.",
    phone: "+14155551234",
  } satisfies ContactForm,
  bugReport: {
    name: "Sam Lee",
    email: "sam@example.com",
    subject: "Bug: login fails on Safari",
    message: "Steps to reproduce: open login, click submit, page hangs.",
  } satisfies ContactForm,
} as const;
```
