The below textbox is printing the value of the phone number after getting it from the database.
-
2020-12-12 00:33
const formatPhoneNumber = (phoneNumber) => {
// convert the raw number to (xxx) xxx-xxx format
const x = phoneNumber && phoneNumber.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/);
return !x[2] ? x[1] : `(${x[1]}) ${x[2]}${x[3] ? `-${x[3]}` : ''}`;
};
console.log(formatPhoneNumber("1111111111"));
|