How do I strip any characters out of the telephone

2019-06-02 18:58发布

How do I strip any characters that are not a number out of the telephone field, including spaces. I need to have a string of numbers 0-9. No () or spaces.

i have a maskedinput for telephone (999) 999-9999

Phone Number:         
<input id="phone" type="text" />   (999) 999-9999 

i just need 9999999999

i am using maskedinput plugin http://digitalbush.com/projects/masked-input-plugin/

2条回答
在下西门庆
2楼-- · 2019-06-02 19:21

http://jsfiddle.net/tylermwashburn/YsHjR/

var phonenum = "(123) 456-7890",
    notnum = /\D/g;

phonenum = phonenum.replace(notnum, '');

alert(phonenum);

This should form it nicely.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-06-02 19:38
var str = "(999) 999-9999";

str = str.replace(/\D/g,'');

Removes anything that is not a digit \D.

查看更多
登录 后发表回答