Example on focus out I want to check if the input has any characters that are not in english. Is this possible in JavaScript?
Asked
Active
Viewed 557 times
0
-
Maybe duplicate of [only-allow-english-characters-and-numbers-for-text-input](https://stackoverflow.com/questions/7144167/only-allow-english-characters-and-numbers-for-text-input) – sugars Nov 06 '19 at 01:41
-
What do you mean by `english characters`? only allow a-z, A-Z? – Max Peng Nov 06 '19 at 01:44
-
`if(inputElement.value.match(/^[a-z0-9_ ]+$/i)){ /* it's English */ }`. Add any special characters you need at the end of those square brackets, after the white space. – StackSlave Nov 06 '19 at 01:45
1 Answers
1
Keeping this very simple.
document.getElementById('test').onkeyup = function(){
if(this.value.match(/^[a-z0-9_.,'"!?;:& ]+$/i)){
console.log('English');
}
else{
console.log('Not English');
}
}
<input id='test' value='' />

StackSlave
- 10,613
- 2
- 18
- 35