开发者

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

开发者 https://www.devze.com 2023-01-29 06:00 出处:网络
This question already has answers here: Closed 12 years ago. 开发者_运维知识库 Possible Duplicate:
This question already has answers here: Closed 12 years ago. 开发者_运维知识库

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


How about regular expressions?

Try something something like:

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


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


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

精彩评论

暂无评论...
验证码 换一张
取 消