Let me explain my question by some examples;
// expected result: ("true" means "rlt" and "false" means "ltr")
var test = "..!"; // true
var test = "te"; // false
var test = "!te"; // false
var test = "..ق"; // true
var test = "مب"; // true
var test = "eس"; // false
var test = "سe"; // true
Here is my current code:
// declare direction of comment in textarea
var x = new RegExp("[A-Za-z]"); // is ascii
var isAscii = x.test($("#textarea-edit-"+post_id_for_edit).val().substring(0, 1));
if(isAscii){
$("#textarea-edit-"+post_id_for_edit).css("direction", "ltr");
} else {
$("#textarea-edit-"+post_id_for_edit).css("direction", "rtl");
}
I want it be based on the first character which is a letter (either Persian or English). But my code is based on the first character (it can be anything, even a sign).
Well how can I do that?