Skip to content

Instantly share code, notes, and snippets.

@zumoshi
Last active August 6, 2020 10:56
Show Gist options
  • Select an option

  • Save zumoshi/cb04825699693f33b081 to your computer and use it in GitHub Desktop.

Select an option

Save zumoshi/cb04825699693f33b081 to your computer and use it in GitHub Desktop.
Convert Persian Numbers to Latin Numbers
/*
tabdil('۲۰۲۷۰۱-۱-۳۸۱-۹۴۳۸۲') => "202701138194382"
*/
var tabdil=function(m){
var num=JSON.parse('{"۰":"0","۱":"1","۲":"2","۳":"3","۴":"4","۵":"5","۶":"6","۷":"7","۸":"8","۹":"9"}');
return m.replace(/./g,function(c){
return (typeof num[c]==="undefined")?
((/\d+/.test(c))?c:''):
num[c];
})
}
function num(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;
}
@shahind
Copy link

shahind commented Aug 6, 2020

yes it works, it seems that a denotes to Arabic and p denotes to Persian digits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment