<input id="myInput" onblur="myFunction()">
<script>
function myFunction() {
var value= document.getElementById('myInput').value;
var regexCharacter = /[0-9|,]+/g;
strFirst = value.replace(regexCharacter, '')
document.getElementById('myInput').value = strFirst
}
</script>
I want to replace '' when the input does not match the regex's. My regex just allow input number and comma. My function is replace when input matching, i want to replace when it's not matching. E.g a12,b2a => 12,2 can anyone help me, thanks.
12,b2aan allowed input, given that it contains letters?