Created
July 6, 2014 08:21
-
-
Save Bersam/57082a1f9e35e399fa96 to your computer and use it in GitHub Desktop.
toPersianNumber function
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
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