We have a string that contains a phone number.
To extract digits we use the replace method.
We replace all symbols that are not digits with the empty string.
All that remains is a phone number.
let string = 'mob. phone: +1 (234) 56-78-901'; let phoneNumber = string.replace(/\D/g, ''); console.log(phoneNumber, string);
I hope you found this article useful, if you need any help please let me know in the comment section.
👋 See you next time. Have a nice day!
Subscribe to our channel: