Extract only the numbers from a Javascript text box

3

How do I extract the numeric value of a text box in javascript, eg:

valor imputado = 1a321q00
valor extraido e adicionado na variável = 132100

Thanks to anyone who helps me

    
asked by anonymous 11.08.2016 / 22:25

3 answers

3

You can filter the value of the field:

var valor_extraido = valor_extraido.replace(/[^0-9]/g,'');
    
11.08.2016 / 22:27
3

You can use the regular expression to replace all non-numeric characters, this is represented by \D , g at the end means that substitution is done on all found elements by default (without g ) only a replacement is done.

"1a321q00".replace(/\D/g, "")
    
11.08.2016 / 22:28
0

You can set the input with type number :

<input type="number" />

Detail is that the and character can be used because it means exponentiation .

    
12.08.2016 / 00:36