I'm trying to validate this kind of phone number in regEx in React (044) 456-7890
.
Check codesanbox here CLICK HERE
Code
const telRegExp = "(d{3})s*d{3}-d{4}";
let validateSchema = yup.object().shape({
tel_no: yup.string().matches(telRegExp, "Telephone number is invalid")
});
<InputMask
mask="(999) 999 - 9999"
onChange={handleChange}
onBlur={handleBlur}
>
{() => (
<TextField
label="Telephone Number (Ex: (044) 878 - 3900)"
name="tel_no"
fullWidth
variant="outlined"
helperText={touched.tel_no ? errors.tel_no : ""}
error={touched.tel_no && Boolean(errors.tel_no)}
/>
)}
</InputMask>