This code is wonderful, you choose the regular expression model that you want, if the character is not allowed, it is deleted.
<script type="text/javascript">
var r={
'special':/[\W]/g,
'quotes':/['\''&'\"']/g,
'notnumbers':/[^\d]/g,
'notletters':/[A-Za-z]/g,
'numbercomma':/[^\d,]/g,
}
function valid(o,w){
o.value = o.value.replace(r[w],'');
}
</script>
HTML
<input type="text" name="login" onkeyup="valid(this,'numbercomma')" />
source
share