TextArea LTR / RTL

I have a simple html textarea, the body has an RTL style, and therefore textarea inherits the style from the body. Therefore, the problem is as follows.

Problem: I need to display the following text in the text area using $ ("# myTextArea"). Val ("text from ajax result comes here").

The text is as follows

پاکستان کا کل رقبہ 796096-0-0 مربع کلو میٹرز ہے۔

and the rest of the text is similar and takes several lines. Now the number in the text of Urdu is 796096-0-0, but it displays the opposite. There are several such numbers in the text. Please tell me so that I can display the numbers as LTR and the rest of the text as RTL, as usual.

Thank.

+1
source share
3 answers

RegEx . , , .

:

var textAreaValue = "پاکستان کا کل رقبہ 796096-0-0 مربع کلو میٹرز ہے۔";

// This regex string means to match a digit, dash, digit, dash, then 6 digits.
var matches = textAreaValue.match("[0-9]{6}\-[0-9]-[0-9]");

if(matches) { // Check that a match happened (multiple allowed)
    for(i = 0; i < matches.length; i++) {
        var reverseValue = matches[i].split("").reverse().join("");
        textAreaValue = textAreaValue.replace(matches[i], reverseValue);
    }
}

// textAreaValue is now پاکستان کا کل رقبہ 0-0-690697 مربع کلو میٹرز ہے۔
$("#myTextArea").val(textAreaValue);
0

ltr. .

0
// str = "پاکستان کا کل رقبہ 796096-0-0 مربع کلو میٹرز ہے۔";
str = str.replace(/([-0-9]+)/g, "\u202a$1\u202c");

CSS direction, rtl, "\u202E" , ( ).

Unicode:

  • U + 202A:
  • U + 202C: - ( , )
  • U + 202E:

: http://www.iamcal.com/understanding-bidirectional-text/

0

All Articles