How to write a cell phone number in an international way using JavaScript ? Last Updated : 31 Dec, 2019 Comments Improve Suggest changes Like Article Like Report E.164 format is used to convert a phone number into an international format. It is an internationally recognized standard that defines a general numbering plan. The international number format according to E.164 is as follows: [+][country code][area code][local phone number] +: Plus sign country code: International country code. It comes after the plus sign. For ex. It is +91 for India whereas it is +1 for USA. area code: It follows after the international country code. India area codes usually have 2, 3 or 4 digits. For ex. In India, Kolkata has an area code of 3211 and Mumbai has area code of 22. local phone number: Local phone number Prerequisite article: How to write Regular Expressions? Concept of regular expressions is used for converting a cell phone number into international way. Regular expressions are a generalized way to match patterns with sequences of characters. Some examples according to the E.164 format Without international code localNumber: 9760064000 intlNumber: (976) 006-4000 With international code localNumber: 919760064000 intlNumber: +91 (976) 006-4000 Example 1: This code uses the regular expression /^(\d{3})(\d{3})(\d{4})$/ for validating the phone numbers. If the number is found to be valid then an array will be returned and if not then null will be returned. The elements of the returned array is then joined according to the E.164 format for international number. Program: html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title> Cell phone number in an International way </title> <style> body { text-align: center; } h1 { color: green; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h3> Cell phone number in an International way </h3> <script> var localNumber = prompt("Please enter your number"); // Using regular expression to check whether // string is valid or not var newArray = localNumber.match (/^(91|)?(\d{3})(\d{3})(\d{4})$/); // Checking the international code var intlCountryCode = (newArray[1] ? '+91' : ''); // Resolving the above array we get // the international number var internationalNumber = intlCountryCode + ' (' + newArray[2] + ') ' + newArray[3] + '-' + newArray[4]; document.write("The number in international" + "form is: " + internationalNumber); </script> </body> </html> Output: Example 2: This code uses the regular expression /^(91|)?(\d{3})(\d{3})(\d{4})$/ for validating the phone numbers with international code. The same approach as above is followed to get the phone number in international format. Program: html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title> Cell phone number in an International way </title> <style> body { text-align: center; } h1 { color: green; } </style> </head> <body> <h1>GeeksforGeeks</h1> <h3> Cell phone number in an International way </h3> <script> var localNumber= prompt("Please enter your number"); // Using regular expression to check // whether string is valid or not var newArray = localNumber.match (/^(91|)?(\d{3})(\d{3})(\d{4})$/); // Checking the international code var intlCountryCode=(newArray[1]?'+91':''); // Resolving the above array we get // the international number var internationalNumber = intlCountryCode + ' (' + newArray[2] + ') ' + newArray[3] + '-' + newArray[4]; document.write("The international number is: " + internationalNumber); </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to write a cell phone number in an international way using JavaScript ? R RitikGarg2 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Misc Similar Reads JavaScript - Convert a Number into JS Array You have a number, like 12345, and you need to convert it into an array where each element represents a digit of the number. For example, 12345 should become [1, 2, 3, 4, 5]. How can you achieve this in JavaScript?In JavaScript, there are various ways to transform a number into an array of its digit 3 min read How to generate a n-digit number using JavaScript? The task is to generate an n-Digit random number with the help of JavaScript. You can also generate random numbers in the given range using JavaScript. Below are the approaches to generate a n-digit number using JavaScript: Table of Content Using Math.random()Math.random() Method and .substring() Me 2 min read How to get decimal portion of a number using JavaScript ? Given a float number, The task is to separate the number into integer and decimal parts using JavaScript. For example, a value of 15.6 would be split into two numbers, i.e. 15 and 0.6 Here are a few methods discussed. These are the following methods: Table of Content Javascript String split() Method 3 min read Generate Random Number in Given Range Using JavaScript Here are the different ways to generate random numbers in a given range using JavaScript1. Using Math.random(): basic ApproachThis is the simplest way to generate a random number within a range using Math.random().JavaScriptlet min = 10; let max = 20; let random = Math.floor(Math.random() * (max - m 3 min read How to convert long number into abbreviated string in JavaScript ? We are given a long number and the task is to convert it to the abbreviated string(eg.. 1234 to 1.2k). Here 2 approaches are discussed with the help of JavaScript.Approaches to Convert Long Number to Abbreviated String:Table of ContentUsing JavaScript methodsUsing Custom functionUsing logarithmsUsin 6 min read How to check first number is divisible by second one in JavaScript ? Given two numbers and the task is to check the first number is divisible by the second number or not with the help of JavaScript. Before getting into the coding part, first let us know about the modulo operator and triple equals. To find a number is divisible by another or not, we simply use the rem 2 min read JavaScript - How to Get a Number of Vowels in a String? Here are the various methods to get the number of vowels in a string using JavaScript.1. Using a for LoopThis is the most basic and beginner-friendly approach. It uses a loop to iterate over each character and checks if it is a vowel.JavaScriptconst cVowels = (s) => { const vowels = "aeiouAEIOU"; 3 min read How to limit a number between a min/max value in JavaScript ? We can limit a number between a min/max value using the is-else condition and using the Math.min and Math.max methods of JavaScript.Below are the approaches to limit a number between a min/max value in JavaScript:Table of ContentUsing the if-else conditionUsing the Math.min() and Math.max() methodsU 2 min read How to convert a pixel value to a number value using JavaScript ? In this article, we will see how to convert the string value containing 'px' to the Integer Value with the help of JavaScript. There are two approaches to converting a pixel value to a number value, these are: Using parseInt() MethodUsing RegExpApproach 1: Using parseInt() Method This method takes a 2 min read How to count number of data types in an array in JavaScript ? Given an array and the task is to count the number of data types used to create that array in JavaScript. Example: Input: [1, true, "hello", [], {}, undefined, function(){}] Output: { boolean: 1, function: 1, number: 1, object: 2, string: 1, undefined: 1 } Input: [function(){}, new Object(), [], {}, 2 min read Like