I'm trying to validate a phone number with Yup:
phone: Yup.number() .typeError("That doesn't look like a phone number") .positive("A phone number can't start with a minus") .integer("A phone number can't include a decimal point") .min(8) .required('A phone number is required'),
.min(8)
validates that the number is 8 or more. So simply entering 8
will pass. How can I make 8 characters required so 1000 0000
would pass?
shape({ phone: yup . string() // regexr.com/6anqd . matches(/(\+91\ )[6-9]{1}[0-9 ]{4}[0-9 ]{4}[0-9]{3}/, { message: "Invalid Indian number", excludeEmptyString: false, }) . required(), email: yup.
1. Google. This is the brute force method of identifying a phone number, but it's quick, easy, and completely free. If the call is from an official or otherwise public source, a search engine like Google or DuckDuckGo might come up with every last detail about the location and owner of the phone number.
Hi right now I'am solving same problem as you and I found possible solution.
Validate phone number with string that matches Regex
const phoneRegExp = /^((\\+[1-9]{1,4}[ \\-]*)|(\\([0-9]{2,3}\\)[ \\-]*)|([0-9]{2,4})[ \\-]*)*?[0-9]{3,4}?[ \\-]*[0-9]{3,4}?$/ phoneNumber: Yup.string().matches(phoneRegExp, 'Phone number is not valid')
You can search for different Regex Expressions and validate it. I've used Regex from this article https://www.sitepoint.com/community/t/phone-number-regular-expression-validation/2204
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With