Created
May 7, 2017 10:27
-
-
Save KhaledElAnsari/0ebd2c266f6feda030042031ce3eff87 to your computer and use it in GitHub Desktop.
Convert Arabic/Persian Numbers to English Numbers
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
var tabdeel = function(m) { | |
var indianDigits = [ | |
'٠', // Zero | |
'١', // One | |
'٢', // Two | |
'٣', // Three | |
'٤', // Four | |
'٥', // Five | |
'٦', // Six | |
'٧', // Seven | |
'٨', // Eight | |
'٩', // Nine | |
]; | |
var arabicDigits = [ | |
"0", | |
"1", | |
"2", | |
"3", | |
"4", | |
"5", | |
"6", | |
"7", | |
"8", | |
"9", | |
]; | |
return m.replace(/[٠-۹]/g, function(c) { | |
return englishDigits[indianDigits.indexOf(c)]; | |
}) | |
}; | |
alert(tabdeel("٠٧٨٦١١٥٦٦٥")); | |
/** | |
* Here's a working fiddle : https://jsfiddle.net/khaledelansari/8afjqn14/2/ | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment