I want to restrict html input, so user cannot input char # into the input
i tried to use pattern but it seems not working
i add these pattern to my input pattern="[^-#]+"
i expect the user cannot input char #, but it still can, what was wrong?
I want to restrict html input, so user cannot input char # into the input
i tried to use pattern but it seems not working
i add these pattern to my input pattern="[^-#]+"
i expect the user cannot input char #, but it still can, what was wrong?
Use a key up event and use replace() to replace # with empty string ''.
<script>
function validateInput()
{
var data = document.getElementById("input").value;
data = data.replace('#','');
document.getElementById("input").value = data;
}
</script>
<input type="text" id="input" onkeyup="validateInput()" />
This worked for me.
Place your logic in onkeydown or onkeypress event handler function. find out the charCode. It must be 35. Then simply event.preventDefault() if the condition is met.
use replace function to replace # with space on keyup or oninput event.
<input type="text"
oninput="this.value = this.value.replace(/#/g, '')" />