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()" />
patternwon't stop users from typing in those characters. You'd have to use keyup event