How can I make an expression or function to get only numbers and commas, which the user informs.
I want to get a product pricing form. If the user types a letter or something other than the comma, it will not be validated. I have the example with just numbers, but I do not have to get a comma:
javascript:
function soNumeros(numeros) { //variavel do parametro recebe o caractere digitado//
return numeros.replace(/\D/g,"");
}
Form:
<label="soNumeros">
Só números: <input id="numeros" onkeypress="mascara(this, soNumeros)" maxlength="11"/>
</label>
Then just call the function in the form using onkeypress.