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:
08053303925
09055303925
08145327190
*/
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 (0)

All DEV content is created by the community!

Hey, if you're landing here for the first time, you should know that this website is a global community of folks who blog about their experiences to help folks like you out.

Sign up now if you're curious. It's free!