html强制转换为数字,在html页面中将英文数字转换为阿拉伯数字

P9Q.. 5 将英语(拉丁)数字转换为波斯数字和阿拉伯数字。 //English to Persian digits. String.prototype.t

P9Q..

5

将英语(拉丁)数字转换为波斯数字和阿拉伯数字。

//English to Persian digits.

String.prototype.toFa= function() {

return this.replace(/\d/g, d => '??????????'[d])

}

//English to Arabic digits.

String.prototype.toAr= function() {

return this.replace(/\d/g, d => '??????????'[d])

}

//English to either Persian or Arabic digits.

String.prototype.toIn= function(e) {

return this.replace(/\d/g, d => e ? '??????????'[d] : '??????????'[d])

}

//English to Persian digits using unicode.

String.prototype.toFaUni= function() {

return this.replace(/\d/g, d => String.fromCharCode('0x06F'+d))

}

//English to Arabic digits using unicode.

String.prototype.toArUni= function() {

return this.replace(/\d/g, d => String.fromCharCode('0x066'+d))

}

//English to either Persian or Arabic digits.

String.prototype.toInUni= function(e) {

return this.replace(/\d/g, d => String.fromCharCode('0x06'+(e ? '6':'F')+d))

}

//examples

let text = 'It is 30/08/2018 at 8:24 AM'

//using array

alert(text.toFa())

alert(text.toAr())

alert(text.toIn(0))

alert(text.toIn(1))

//using unicode

alert(text.toFaUni())

alert(text.toArUni())

alert(text.toInUni(0))

alert(text.toInUni(1))