Skip to content

Instantly share code, notes, and snippets.

@faridv
Created July 27, 2017 08:42
Show Gist options
  • Save faridv/0dad15cd717d979c77a466cd7e3e45a5 to your computer and use it in GitHub Desktop.
Save faridv/0dad15cd717d979c77a466cd7e3e45a5 to your computer and use it in GitHub Desktop.
Convert Persian digits to Latin digits
function persianToLatinDigits (s) {
var a = ["٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"];
var p = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"];
for (var i = 0; i < 10; i++) {
s = s.replace(new RegExp(a[i], 'g'), i).replace(new RegExp(p[i], 'g'), i);
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment