How to get Phone number in certain format and separate them by comma - Javascript

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to get Phone number in certain format and separate them by comma - Javascript



I want to get list of phone numbers in a string.
Example string :


var str = "This my phone number 0123456780, my turn no is 42, my second phone number is 01234567890";

var no = parseInt(str.replace(/[^0-9]/g,''));
console.log(no);



So, expected result I want like below, if multiple phone number existing, will be separated by comma:

"60123456780, 601234567890".


"60123456780, 601234567890"



Thanks





how can you expect, from the code you wrote, a string, since you parseInt - and where does the leading magic 6 come from?
– Jaromanda X
12 mins ago




parseInt


6





Please include your full code. Very similar questions have been asked before on this site.
– Tim Biegeleisen
11 mins ago





Possible duplicate of How do I retrieve all matches for a regular expression in JavaScript?
– Tim Biegeleisen
10 mins ago





str.match(/d{10}/g).map(n => `6${n}`).join(', ')
– Jaromanda X
10 mins ago




str.match(/d{10}/g).map(n => `6${n}`).join(', ')





Thanks @JaromandaX, your code is working and I appreaciate, But how if first number length is 10 and second number length is 11 as my example below. "60123456780, 601234567890"
– Mohamad Izzuddin
just now









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

C# - How to create a semi transparent or blurred backcolor on windows form

Will Oldham

Makefile test if variable is not empty