Remove all non-digit characters from a string jquery? [duplicate]

情到浓时终转凉″ 提交于 2019-12-21 12:42:27

问题


Possible Duplicate:
Javascript: strip out non-numeric characters from string

String matching is headache for me.

Example:

If I have strings like these:

abc123xyz456()*
^%$111u222

Then convert it to:

123456
111222

回答1:


How about regular expressions?

Try something something like:

'abc123xyz456()*'.replace(/\D/g,'') 



回答2:


<input id='num' value='hgjhGJHGt7y67ihgGUT&6tb.,.,z.oy8'/>


$('#num').val($('#num').val().replace(/[^\d]/g, ""));


来源:https://stackoverflow.com/questions/4388055/remove-all-non-digit-characters-from-a-string-jquery

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