Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AmrMekkawy/326cdeb04343ff54da99f8b428869425 to your computer and use it in GitHub Desktop.
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
$('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