← All Learning Paths

Form Validation Specialist

Validate at the right layer: schema-first architecture, server-side trust boundaries, typed resolvers, accessible error messages, and tests for every rejection path.

technicalbeginner13 nodes13h total

Path overview

表单校验的深坑不在语法,而在层次:客户端、服务端与 Schema 各守哪层。本路径从架构文章讲起,经 Zod 与 React Hook Form 的类型化组合,覆盖原生、Go、Python 多栈实现,收尾于三道递进练习。

The hard part of form validation is layering: what belongs to the client, the server, and the schema. This path covers schema-first architecture, typed resolvers, multi-stack implementations, and exercises.

  1. Read "Form Validation Architecture: From Schema to UI" for the "Why a Single Schema Is the Source of Truth" argument, then name the decision in forms work it would change.

    Completion criteria: Attach a one-page summary that quotes "Why a Single Schema Is the Source of Truth", lists two trade-offs, and links the commit where you applied it.

    Next step: Zod

    ⏱ 1h

  2. Read "Zod"'s documented surface around "z.string z.string(): ZodString", then build a minimal endpoint and log the response.

    Prerequisites: Form Validation Architecture: From Schema to UI

    Completion criteria: Attach one successful call and one invalid call against "Zod", citing "TypeScript-first schema validation with static type inference for runtime data parsing and" as the documented surface.

    Next step: React Hook Form

    ⏱ 1h

  3. Stand up "React Hook Form" for a forms task, confirm "useForm useForm<TFieldValues>(options?: UseFormProps<TFieldValues>):" holds, and document one failure you triggered.

    Prerequisites: Zod

    Completion criteria: Run a request against "React Hook Form", paste the response, and add one deliberately invalid call with its error.

    Next step: React Hook Form Zod Typed Resolver

    ⏱ 1h

  4. Run the forms snippet "React Hook Form Zod Typed Resolver", capture stdout, and show which line demonstrates the documented behavior: "Wire React Hook Form to a Zod resolver so field rules live in one schema, errors arrive".

    Prerequisites: React Hook Form

    Completion criteria: Paste the command, the exit code, and the output line matching "Wire React Hook Form to a Zod resolver so field rules live in one schema, errors arrive"; then show a second run with a changed parameter.

    Next step: React Form Validation with Custom Hook

    ⏱ 0.75h

  5. Adapt "React Form Validation with Custom Hook" to a second input and compare the new output with the behavior described in "Validate React form fields using a custom useForm hook with real-time error messages,".

    Prerequisites: React Hook Form Zod Typed Resolver

    Completion criteria: Save two runs of "React Form Validation with Custom Hook" side by side — the original input and one changed value — and annotate the line where the output diverges.

    Next step: Vanilla JavaScript Form Validation

    ⏱ 0.75h

  6. Execute "Vanilla JavaScript Form Validation", change one constant, and describe how the output diverges from "Validate HTML forms with vanilla JavaScript using the Constraint Validation API.".

    Prerequisites: React Form Validation with Custom Hook

    Completion criteria: Attach the terminal transcript for "Vanilla JavaScript Form Validation": command, exit code, and the printed result you used to confirm "Validate HTML forms with vanilla JavaScript using the Constraint Validation API.".

    Next step: Go Form Validation with Struct Tags

    ⏱ 0.75h

  7. Run the forms snippet "Go Form Validation with Struct Tags", capture stdout, and show which line demonstrates the documented behavior: "Validate form data in Go using struct tags with the validator package, custom validation".

    Prerequisites: Vanilla JavaScript Form Validation

    Completion criteria: Change one constant in "Go Form Validation with Struct Tags", rerun, and attach both stdout captures plus a one-line diff explaining what moved.

    Next step: FastAPI Form Validation with Pydantic

    ⏱ 0.75h

  8. Adapt "FastAPI Form Validation with Pydantic" to a second input and compare the new output with the behavior described in "Validate form data in FastAPI using Pydantic models with custom validators, field".

    Prerequisites: Go Form Validation with Struct Tags

    Completion criteria: Save two runs of "FastAPI Form Validation with Pydantic" side by side — the original input and one changed value — and annotate the line where the output diverges.

    Next step: How to Validate Forms in React with Custom Hooks

    ⏱ 0.75h

  9. Reconstruct the reasoning behind "How to Validate Forms in React with Custom Hooks" by tracing "Define typed values and rules" to the failure it prevents in forms systems.

    Prerequisites: FastAPI Form Validation with Pydantic

    Completion criteria: Attach a one-page summary that quotes "Define typed values and rules", lists two trade-offs, and links the commit where you applied it.

    Next step: HTML5 Form Validation Attributes

    ⏱ 1h

  10. Solve "HTML5 Form Validation Attributes": turn Validated form submission into browser validates format and pass the provided samples.

    Prerequisites: How to Validate Forms in React with Custom Hooks

    Completion criteria: Show a test command that validates "Validated form submission" and "browser validates format" and passes after your fix.

    Next step: Validate a Username with Custom Messages

    ⏱ 0.25h

  11. Implement "Validate a Username with Custom Messages" so that A JSON string with message and valid keys. yields {message:Please enter a username.,valid:false}, including the edge case in the second sample.

    Prerequisites: HTML5 Form Validation Attributes

    Completion criteria: Submit a solution that passes both samples (A JSON string with message and valid keys. to {message:Please enter a username.,valid:false}) and attach the failing case you fixed.

    Next step: Composable Typed Form Validators

    ⏱ 0.5h

  12. Complete "Composable Typed Form Validators" by making A JSON object with valid (boolean) and errors, a map containing only the first error per field. produce {valid:false,errors:{email:INVALID_EMAIL,age:TOO_YOUNG,name:REQUIRED}} without hard-coding the sample.

    Prerequisites: Validate a Username with Custom Messages

    Completion criteria: Attach the solution file, two passing sample runs, and one failing run whose error matches the contract for "{valid:false,errors:{email:INVALID_EMAIL,age:TOO_YOUNG,name:REQUIRED}}".

    Next step: Capstone: Form Validation Specialist

    ⏱ 0.5h

  13. Ship "Type checking for null, boolean, object, array, number, and string including integer" from "Build a JSON Schema Validator from Scratch", then prove it with the project's test suite and an acceptance note.

    Prerequisites: Composable Typed Form Validators

    Completion criteria: Run the project's test command for "Build a JSON Schema Validator from Scratch", paste the passing output, and attach the acceptance note for "Type checking for null, boolean, object, array, number, and string including integer" with the test name.

    Next step: Run the capstone's tests, publish the repository, and demo it to a reviewer.

    ⏱ 4h