I want the user to only be able to enter English characters, the code below works but on a mac if you hold the letter "a" for example you can insert accented characters such as "á". I've tried a few different approaches with keydown, keyup etc but even on the release of the key it thinks the value that was entered is "A" so it gets past the regex. Anyone know whats going wrong or a better way on how to do this please?
$('.monogram-letters').on("keypress", function(e) {
var englishAlphabet = /[A-Za-z]/g;
var key = String.fromCharCode(e.which);
if (englishAlphabet.test(key)) {
console.log('true');
return true;
} else {
console.log('false');
}
return false;
});
$('.monogram-letters').on("paste", function(e) {
e.preventDefault();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="text" value="" class="monogram-letters valid" maxlength="3" id="options-41-container" name="options[41]" data-category="41" data-val="type your letters (up to 3)" required="" aria-required="true" aria-invalid="false">