I have a phone number like (123) 456-7891. I need number like 1234567891.
How can I do that in Javascript ?
To be on the safe side, I would recommend removing everything except +
(for country codes) and digits:
result = subject.replace(/[^+\d]+/g, "");
You can use String.replace() to do this. Pass it a RegExp that matches everything but digits and replace them with ''
.
var number = '(123) 456-7891';
number = number.replace(/[^\d]/g, '');
alert("(123) 456-7891".replace(/[\(\)\-\s]+/g, ''));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With