Skip to content

Instantly share code, notes, and snippets.

@Bersam
Created July 6, 2014 08:21
Show Gist options
  • Save Bersam/57082a1f9e35e399fa96 to your computer and use it in GitHub Desktop.
Save Bersam/57082a1f9e35e399fa96 to your computer and use it in GitHub Desktop.
toPersianNumber function
function toPersianNumber(value) {
if (!value) {
return;
}
var arabicNumbers = ["١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩", "٠"],
persianNumbers = ["۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹", "۰"];
for (var i = 0, numbersLen = arabicNumbers.length; i < numbersLen; i++) {
value = value.replace(new RegExp(arabicNumbers[i], "g"), persianNumbers[i]);
}
return value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment