Convert numerical mobile number (1234567e89) into a proper format

To convert a numerical mobile number into a proper format using JavaScript, you can use the following code snippet:


//Example Google contact mobile number conversion
function formatMobileNumber(number) {
  //format number
  const formattedNumber = number.toString().replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3');
  return formattedNumber;
}
const originalNumber = 1234567e89;
const properFormatNumber = formatMobileNumber(originalNumber);
// Output
console.log(properFormatNumber); 


This code defines a function formatMobileNumber that takes a numerical mobile number as input and returns it in the proper format. The replace method is used to format the number as per the standard pattern for mobile numbers.

Comments

Popular posts from this blog

NVD3 is a JavaScript library that extends the D3.js library

HTML Marquee