DEV Community

Adeyemi Simeon
Adeyemi Simeon

Posted on

Yup Schema for Nigeria Phone Mobile Number

I was trying out Regex to validate Nigerian mobile numbers without the country code (+234).
Here is what I came up with.
Not sure if it is perfect though. Any other ideas?

import * as yup from "yup";

Regex to match Nigeria mobile number with the country code +234
It matches:
const phoneRegExp = /^([0]{1})[0-9]{10}$/

cconst schema = yup.object().shape({
  phone: yup.string().matches(phoneRegex, "Invalid phone number."),

export default schema;

Enter fullscreen mode Exit fullscreen mode

Top comments (1)

aiyeola profile image
Victor Aiyeola

Pardon, this doesn't work