I need to make my input text just accept English letter without spaces or number or can copy and paste in it!
I have tried this code and it works but when I copy and paste anything outside input it accept the value:
const regex = /[A-Za-z]/;
function validate(e) {
const chars = e.target.value.split('');
const char = chars.pop();
if (!regex.test(char)) {
e.target.value = chars.join('');
}
}
document.querySelector('#inputTextBox').addEventListener('input', validate);
How can I make it not allow to copy and paste value out of input?
feel free to use Jquery
or pure JS