简体   繁体   中英

Remove Slashes From the phone Number

How we can Strip USA Phone Number by removing slashes and brackets. I search it from google but i cannot find it.I want to use regex, which will not remove plus sign in the start.

Eg input: +(123) 123/4-1234 output: +12312341234

use this /[^0-9+]/g this will expect only + and numbers.

 run1.onclick = function() { //removes "(" and ")" output1.innerHTML = input1.value.replace(/[^0-9+]/g, ''); }
 <p>Remove () and / and - and space</p> <input id="input1" type="text" value="+(123) 123/4-1234"> <input id="run1" type="button" value="run"> <span id="output1"></span>

Try [^0-9+] it will pass only digits and char +

 let r= "+(123) 123/4-1234".replace(/[^0-9+]/g,'') console.log(r);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM