Skip to content Skip to sidebar Skip to footer

Textarea Ltr/rtl

I have a simple html textarea, the body has RTL style and so textarea inherits the style from body. So the problem is following. Problem: I have to display the following text into

Solution 1:

You can use RegEx to search for the number. If found you can reverse and then replace it.

Example:

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);

Solution 2:

Try to give your text area ltr . Not inherits . May works

Solution 3:

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

You'll have to place this string in a container that has the CSS attribute direction set to rtl, or you'll have to add a "\u202E" character to the beginning, otherwise the sections appeared in reverse order (but in the correct direction).

These are Unicode direction control characters:

  • U+202A: left-to-right embedding
  • U+202C: pop-directional-formatting (basically end of embedding)
  • U+202E: right-to-left override

I've been using this as a reference: http://www.iamcal.com/understanding-bidirectional-text/

Post a Comment for "Textarea Ltr/rtl"