Skip to content

Instantly share code, notes, and snippets.

@KhaledElAnsari
Created May 7, 2017 10:27
Show Gist options
  • Save KhaledElAnsari/0ebd2c266f6feda030042031ce3eff87 to your computer and use it in GitHub Desktop.
Save KhaledElAnsari/0ebd2c266f6feda030042031ce3eff87 to your computer and use it in GitHub Desktop.
Convert Arabic/Persian Numbers to English Numbers
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