Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert double byte integer to single byte-Javascript

Is possible to convert double byte integer to single byte using java script ?? I need to convert double byte numbers as single byte,when it is entered into a text box.Is there any method available in jQuery or javascript.

like image 328
Shijin TR Avatar asked Aug 08 '26 10:08

Shijin TR


1 Answers

There's no built-in way to convert 1 (U+FF11) to 1 (U+0031). You could use a regular expression to do it specifically for the characters you mentioned:

var rex = /[\uFF10-\uFF19]/g;
var str = "1234";

console.log("Before: " + str);  
str = str.replace(rex, function(ch) {
    return String.fromCharCode(ch.charCodeAt(0) - 65248);
});

console.log("After: " + str);

Live Example (be sure to open the JavaScript console) | Source

like image 200
T.J. Crowder Avatar answered Aug 11 '26 00:08

T.J. Crowder