7

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
Community
  • 1
  • 1
Awan
  • 18,096
  • 36
  • 89
  • 131

2 Answers2

25

How about regular expressions?

Try something something like:

'abc123xyz456()*'.replace(/\D/g,'') 
ilivewithian
  • 19,476
  • 19
  • 103
  • 165
3
<input id='num' value='hgjhGJHGt7y67ihgGUT&6tb.,.,z.oy8'/>


$('#num').val($('#num').val().replace(/[^\d]/g, ""));
FatherStorm
  • 7,133
  • 1
  • 21
  • 27