Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]Error validate email #1638

Closed
linhnvg opened this issue Dec 6, 2022 · 1 comment
Closed

[Bug]Error validate email #1638

linhnvg opened this issue Dec 6, 2022 · 1 comment

Comments

@linhnvg
Copy link

linhnvg commented Dec 6, 2022

  • I use zod and react-hook-form when I validate emails but adding a dash at the end doesn't trigger the error

  • I tried using emailRegex in zod doc but no error trigger

  • I'm wondering if the problem is there or not?

  • I tried with yup and got the trigger error

import { useCallback, VFC } from "react";
import { SubmitHandler, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import * as z from "zod";

const auth = z.object({
  email: z
    .string()
    .email("正しいメールアドレスの形式で入力してください"),
  password: z.string()
});


const user = z.object({
  firstName: z
    .string()
    .min(1, { message: "1文字以上入力してください" })
    .max(10, { message: "10文字以下で入力してください" }),
  lastName: z
    .string()
    .min(1, { message: "1文字以上入力してください" })
    .max(10, { message: "10文字以下で入力してください" }),
  phoneNumber: z.string().regex(/^0\d{9,10}$/, {
    message: "正しい電話番号の形式で入力してください"
  }),
  role: z.enum(["admin", "user"])
});

image

image

image

@linhnvg linhnvg changed the title Error validate email [Bug]Error validate email Dec 6, 2022
powerfulyang added a commit to powerfulyang/zod that referenced this issue Dec 7, 2022
powerfulyang added a commit to powerfulyang/zod that referenced this issue Dec 7, 2022
powerfulyang added a commit to powerfulyang/zod that referenced this issue Dec 7, 2022
@colinhacks
Copy link
Owner

colinhacks commented Dec 12, 2022

I recommend using .regex() to use your preferred email validator. There are a lot of opinions on what should be considered a valid email and Zod uses a fairly liberal regex intentionally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants