Created
March 2, 2017 22:49
-
-
Save AmrMekkawy/326cdeb04343ff54da99f8b428869425 to your computer and use it in GitHub Desktop.
Change the direction of the text dynamically based on the user input. Source: http://stackoverflow.com/a/7770258/458204
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('input, textarea').keyup(function(){ | |
$this = $(this); | |
if($this.val().length == 1) | |
{ | |
var x = new RegExp("[\x00-\x80]+"); // is ascii | |
//alert(x.test($this.val())); | |
var isAscii = x.test($this.val()); | |
if(isAscii) | |
{ | |
$this.css("direction", "ltr"); | |
} | |
else | |
{ | |
$this.css("direction", "rtl"); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment