Kenyan Regex Number Formatting Function for Javascript

Kibikukimani
Jun 10, 2022

Here is how to…

var regEx = /^(?:254|\+254|0)?(7(?:(?:[129][0-9])|(?:0[0-8])|(4[0-1]))[0-9]{6})$/;
var phonenumber = '+254721123456'
if (phonenumber.match(regEx)) {
console.log('true');
} else {
console.log('false');
}

Happy Coding!

--

--

Kibikukimani

Kibiku is a Software Engineer fascinated by all things tech, striving to be a master of best Software Engineering principles and best practices of writing code