ProNextJS / forms-management

Form validation and posting example in the NextJS App Router
28 stars 7 forks source link

Code typo on async validation lesson #1

Closed johndjameson closed 7 months ago

johndjameson commented 7 months ago

Thanks for putting this together! I’ve got my whole team working through the course this week 💪

When taking the course myself, I noticed a small typo in the lesson text of the “Implement Async Server-Side Validation” chapter:

https://www.pronextjs.dev/tutorials/forms-management-with-next-js-app-router/forms/implement-async-server-side-validation#building-a-zip-code-validator

In the following code block,

"use server";

export async function validateZipCode(zipCode: string): Promise<boolean> {
  console.log("validateZipcode on SERVER", zipCode)
  return /^/d{5}.test(zipCode) && zipCode.startsWith('9');
}

/^/d{5}.test(zipCode) should be /^\d{5}/.test(zipCode) instead. The original code causes a syntax error crash when used.

Also, validateZipcode.ts is duplicated as validateZipcode.tsx in the repository. There should be only be the .ts one, right?

Thanks again! We’re excited to put this pattern into development ✨

jherr commented 7 months ago

Awesome! Thank you so much for the bug report.

tayiorbeii commented 7 months ago

@johndjameson thanks for catching this-- fixed!