here is my input mask code which i am initializing in a drawcallback function.
$(".clstxtInputNumber").inputmask({
alias: 'decimal',
groupSeparator: ',',
autoGroup: true,
digits: gDomesticOverseas == "M" ? 0 : 2,
digitsOptional: false,
rightAlign: false
});
I want to convert the values double bytes values i-e Japanese IME keypad layout into single bytes values
here is my input element
<input maxLength='15' " + enableDisable + " oninput='javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength)' id='" + ControlId + "' style='max-width: 300px!important;' type="text" name="fname" class="form-control form-control-sm form-control-solid mb-4 mb-lg-0 customInputField clstxtInputText clstxtInputNumber clsRightAlignColumn" onkeypress='return isNumberWithDoubleByte(event)' value='" + data + "' />
i want to apply onkeypress function which will convert the double bytes into single byte,
Is there any way to do this.
this function runs when i comment the inputmask and then it shows perfectly fine values while using english keyboard.
function DoubleToSingleBytesConversion(ele) {
debugger
var currentValue = $(ele).val();
currentValue = currentValue.replaceAll(',', '');
var regex = /^d+(.d*)?$/;
if (currentValue !== "") {
if (currentValue.includes('0')) {
currentValue = currentValue.replaceAll('0', '0');
}
if (currentValue.includes('1')) {
currentValue = currentValue.replaceAll('1', '1');
}
if (currentValue.includes('2')) {
currentValue = currentValue.replaceAll('2', '2');
}
if (currentValue.includes('3')) {
currentValue = currentValue.replaceAll('3', '3');
}
if (currentValue.includes('4')) {
currentValue = currentValue.replaceAll('4', '4');
}
if (currentValue.includes('5')) {
currentValue = currentValue.replaceAll('5', '5');
}
if (currentValue.includes('6')) {
currentValue = currentValue.replaceAll('6', '6');
}
if (currentValue.includes('7')) {
currentValue = currentValue.replaceAll('7', '7');
}
if (currentValue.includes('8')) {
currentValue = currentValue.replaceAll('8', '8');
}
if (currentValue.includes('9')) {
currentValue = currentValue.replaceAll('9', '9');
}
if (currentValue.length > parseInt($(ele).attr('maxlength'))) {
currentValue = currentValue.slice(0, parseInt($(ele).attr('maxlength')))
}
if (regex.test(currentValue)) {
tempVal = currentValue;
tempVal = parseFloat(tempVal).toFixed(2);
tempVal = ConvertToDigitsWithComma(tempVal)
$(ele).val(tempVal);
}
else {
currentValue = currentValue.replace(/[^d,.]/g, '');
tempVal = currentValue;
tempVal = parseFloat(tempVal).toFixed(2);
tempVal = ConvertToDigitsWithComma(tempVal)
$(ele).val(tempVal);
}
}
else {
// $(ele).val("0.00");
}
}
function ConvertToDigitsWithComma(txt) {
if (txt instanceof Element || txt instanceof HTMLDocument) {
let value = txt.value.replace(/,/g, ''); // Remove existing commas, if any
// Convert the value to a comma-separated format
let formattedValue = value.toString().replace(/B(?=(d{3})+(?!d))/g, ",");
// Update the input element's value with the formatted value
txt.value = formattedValue;
} else {
let formattedValue = txt.toString().replace(/B(?=(d{3})+(?!d))/g, ",");
return formattedValue
}
// Return false to prevent any default behavior or propagation
return false;
}
I have create the above function when i debug using browser console this function shows the exactly same values but when i don’t apply debugger it will show values like
what i type : “100000.00”
what input shows : “1100010.00”
Any help will be appreciated.
Thanks in advance