Question and answer is powered by AnsPress.io
Disallow special characters in HTML input
<input name="generateID" type="text" class="form-control">
In my HTML input, I can’t access any special character. If the user enters any special character it is automatically removed from the input. How can I disallow special characters in HTML input?
To disallow special characters in HTML input, apply this code.
onkeyup="this.value=this.value.replace(/[^a-zA-Z0-9]/g, '')"
Example:
<input name="generateID" type="text" class="form-control" onkeyup="this.value=this.value.replace(/[^a-zA-Z0-9]/g, '')">