Forked from MeTe-30/Convert Persian & English digits together
Created
August 7, 2017 13:09
-
-
Save faridv/65fe4b30b6666acac161d7f054b5d375 to your computer and use it in GitHub Desktop.
Convert Persian & English digits together | Javascript
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
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