Created
December 6, 2016 07:53
-
-
Save MeTe-30/ffb289b89af8c11ca6e1e7091cc8c129 to your computer and use it in GitHub Desktop.
Convert Persian & English digits together | Javascript
This file contains hidden or 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
String.prototype.toPersianDigits = function () { | |
var id = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']; | |
return this.replace(/[0-9]/g, function (w) { | |
return id[+w]; | |
}); | |
}; | |
String.prototype.toEnglishDigits = function () { | |
var id = { '۰': '0', '۱': '1', '۲': '2', '۳': '3', '۴': '4', '۵': '5', '۶': '6', '۷': '7', '۸': '8', '۹': '9' }; | |
return this.replace(/[^0-9.]/g, function (w) { | |
return id[w] || w; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment