How do I strip any characters out of the telephone field

耗尽温柔 提交于 2019-12-23 04:05:12

问题


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/


回答1:


var str = "(999) 999-9999";

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

Removes anything that is not a digit \D.




回答2:


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

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

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

alert(phonenum);

This should form it nicely.



来源:https://stackoverflow.com/questions/5227174/how-do-i-strip-any-characters-out-of-the-telephone-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!