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 (1)

Collapse
 
aiyeola profile image
Victor Aiyeola

Pardon, this doesn't work