Created
January 19, 2011 12:33
-
-
Save eAmin/786108 to your computer and use it in GitHub Desktop.
English Digit to Persian
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
/* | |
* 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; | |
}); | |
}; |
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
"012345srh6srh789".toFaDigit(); // ۰۱۲۳۴۵srh۶srh۷۸۹ | |
"۰۱۲۳۴۵srh۶srh۷۸۹".toEnDigit(); // 012345srh6srh789 |
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
/* | |
* 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