I want to check if a number is Arabic , and replace all it’s digits to English so that I can do calculation on it . I’m trying this Function , but I don’t know what regular expression is suitable for it :
function enNumber(num)
{
for (var i=0;i<10;i++)
num=num.replace(*[regular expression]*,i);
return num;}
Minimum solution for the question that was asked
This should solve what you asked for:
General function for all known digits in Unicode class Nd (Number, Decimal Digit)
The function below has support for Unicode class Nd (Number, Decimal Digit):
Adlam, Ahom, Arabic-indic, Balinese, Bengali, Bhaiksuki, Brahmi, Chakma, Cham, Devanagari, Extended Arabic-indic, Fullwidth, Gujarati, Gurmukhi, Javanese, Kannada, Kayah Li, Khmer, Khudawadi, Lao, Lepcha, Limbu, Malayalam, Mathematical Bold, Mathematical Double-struck, Mathematical Monospace, Mathematical Sans-serif Bold, Mathematical Sans-serif, Meetei Mayek, Modi, Mongolian, Mro, Myanmar Shan, Myanmar Tai Laing, Myanmar, New Tai Lue, Newa, Nko, Ol Chiki, Oriya, Osmanya, Pahawh Hmong, Saurashtra, Sharada, Sinhala Lith, Sora Sompeng, Sundanese, Tai Tham Hora, Tai Tham Tham, Takri, Tamil, Telugu, Thai, Tibetan, Tirhuta, Vai, Warang Citi.
There is no support for roman numbers and other non-decimal numbers, because they are not decimal.
Usage:
Module for node.js
A function similar to this one is now available in a node.js module called
unicodedigits. That function can translate from any supported digit to ASCII or any of the supported ranges.You can install it with
npm install unicodedigits --saveor find it on github.com/somec/unicodedigits