Hi nedash,
Refer below code.
HTML
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<input id="txtArabic" type="text" placeholder='Type Arabic'>
<br />
["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"]
<br />
["٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"]
<script type="text/javascript">
window.onload = function () {
document.getElementById('txtArabic').addEventListener('input', function () {
var v = transformNumbers.toEnglish(this.value);
this.value = this.value ? (+v).toLocaleString('ar-EG') : '';
});
}
var transformNumbers = (function () {
var numerals = {
persian: ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"],
arabic: ["٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"]
};
function fromEnglish(str, lang) {
var i, len = str.length, result = "";
for (i = 0; i < len; i++)
result += numerals[lang][str[i]];
return result;
}
return {
toEnglish: function (str) {
var num, i, len = str.length, result = "";
for (i = 0; i < len; i++) {
num = numerals["persian"].indexOf(str[i]);
num = num != -1 ? num : numerals["arabic"].indexOf(str[i]);
if (num == -1) continue // num = str[i];
result += num;
}
return result;
},
toPersian: function (str, lang) {
return fromEnglish(str, "persian");
},
toArabic: function (str) {
return fromEnglish(str, "arabic");
}
}
})();
</script>
</body>
</html>
Screenshot
Reference :
https://stackoverflow.com/questions/50319819/separate-thousands-while-typing-in-farsipersian