Last active
July 27, 2021 12:26
-
-
Save baras/643c22e2d30c20136bde6193e743b610 to your computer and use it in GitHub Desktop.
Set input / textarea direction to rtl if the field contains RTL characters.
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
$(document).on('input', 'input, textarea', function () { | |
var $el = $(this), | |
val = $el.val(); | |
if (val.length) { | |
$el.css({direction: isRTL(val) ? 'rtl' : 'ltr'}); | |
} else { | |
$el.css({direction: ""}); | |
} | |
}); | |
function isRTL(s) { | |
return (/[\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC]/).test(s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment