tone
tone

Reputation: 1555

JS Regex allow single language input

I need javascript regex that will allow english or hebrew characters but not both mixed. for example:

Upvotes: 5

Views: 764

Answers (1)

agent-j
agent-j

Reputation: 27943

Matches strings entirely of the Hebrew unicode range, or entirely alpha/numeric/underscore.

/^(?:[\u0590-\u05FF\uFB1D-\uFB40]+|[\w]+)$/i

Got the Hebrew unicode ranges from wikipedia.

var RE_SINGLE_LANG = /^(?:[\u0590-\u05FF\uFB1D-\uFB40]+|[\w]+)$/i;
if (!RE_SINGLE_LANG.exec(myText)) {
   alert("NOT VALID");
}

Upvotes: 4

Related Questions