DumbDevGirl42069
DumbDevGirl42069

Reputation: 959

How can I validate if the characters in a text input are english characters?

Example on focus out I want to check if the input has any characters that are not in english. Is this possible in JavaScript?

Upvotes: 0

Views: 1189

Answers (1)

StackSlave
StackSlave

Reputation: 10627

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='' />

Upvotes: 1

Related Questions