Skip to content

Instantly share code, notes, and snippets.

@eAmin
Created January 19, 2011 12:33
Show Gist options
  • Save eAmin/786108 to your computer and use it in GitHub Desktop.
Save eAmin/786108 to your computer and use it in GitHub Desktop.
English Digit to Persian
/*
* English digit to persian
* Copyright(C) 2009 by Amin Akbari [ http://eAmin.me/ ]
* Licensed under the MIT Style License [http://www.opensource.org/licenses/mit-license.php]
*
*/
String.prototype.toFaDigit = function() {
return this.replace(/\d+/g, function(digit) {
var ret = '';
for (var i = 0, len = digit.length; i < len; i++) {
ret += String.fromCharCode(digit.charCodeAt(i) + 1728);
}
return ret;
});
};
"012345srh6srh789".toFaDigit(); // ۰۱۲۳۴۵srh۶srh۷۸۹
"۰۱۲۳۴۵srh۶srh۷۸۹".toEnDigit(); // 012345srh6srh789
/*
* Persian digit to English
* Copyright(C) 2009 by Amin Akbari [ http://eAmin.me/ ]
* Licensed under the MIT Style License [http://www.opensource.org/licenses/mit-license.php]
*
*/
String.prototype.toEnDigit = function() {
return this.replace(/[\u06F0-\u06F9]+/g, function(digit) {
var ret = '';
for (var i = 0, len = digit.length; i < len; i++) {
ret += String.fromCharCode(digit.charCodeAt(i) - 1728);
}
return ret;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment