Input Box Restrictions
Keep data clean. This script intercepts user input and strips out any characters that do not match your allowed pattern.
Copy the Script
<!-- Allow Numbers Only -->
<input type="text" oninput="this.value = this.value.replace(/[^0-9]/g, '')">
<!-- Allow Letters Only -->
<input type="text" oninput="this.value = this.value.replace(/[^a-zA-Z]/g, '')">
<!-- Allow Alphanumeric (No symbols) -->
<input type="text" oninput="this.value = this.value.replace(/[^a-zA-Z0-9]/g, '')">
Frequently Asked Questions
Yes, that is preferred for mobile keyboards. However, `type='number'` sometimes allows characters like 'e' (exponential). This script ensures *strict* restrictions.
Yes. By using the `oninput` event, the regex replacement runs even if text is pasted in, stripping out invalid characters instantly.
Yes. Just update the regex to allow only alphanumeric characters: `value.replace(/[^a-zA-Z0-9]/g, '')`.