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

Custom Error Message #706

Open
younes-alouani opened this issue Apr 23, 2022 · 3 comments
Open

Custom Error Message #706

younes-alouani opened this issue Apr 23, 2022 · 3 comments

Comments

@younes-alouani
Copy link

How to make a custom error message ?

I tried something like this :

phoneNumber: Yup.string().phone(errorMessage="Please enter a valid phone number, include the country and area codes."),

But it does not work.

@tkmmoise
Copy link

// validate phone number strictly in the given region with custom error message
const phoneNumber= yup.string()
.phone('IN', true, '${path} is invalid')
.required();

try this

@darkkatarsis
Copy link

Ok, what if I don't want to specify the region?

@jeffal
Copy link

jeffal commented Jun 6, 2023

Seems to be working for me if I set phone(undefined, false, "Custom Error Message"). If undefined the defaults will kick in: https://github.com/abhisekp/yup-phone/blob/master/src/yup-phone.ts#L44C1-L46

The country code is only used if strict is true.

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

4 participants