So, this is my input field:
How can I allow only English letters?
This is the RegEx>
You could use /[A-Za-z]/ regular expression and an input event handler which is fired every time the value of the element changes. Something like below:
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('');
console.log(`${char} is not a valid character.`);
}
}
document.querySelector('#myInput').addEventListener('input', validate);