Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS Regex allow single language input

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

  • myuser - OK.
  • myאבג - NOT OK.
  • אבגדה - OK.
like image 426
tone Avatar asked Oct 11 '22 16:10

tone


1 Answers

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");
}
like image 115
agent-j Avatar answered Oct 13 '22 06:10

agent-j