Hello people.
I am working on a form and when the customer enter numbers in a input, i need it appears instantly one point every three digits in the same field, like this: 1111111 —> 1 . 111 . 111
I’ve got the next code, but im new and its really difficult make this work.
function formatNumber(num) {
return num
.replace(",", ".") // replace decimal point character
.replace(/(\d)(?=(\d{3})+(?!\d))/g);
}
export function input3_change(event, $w) {
let num = parseFloat($w("#input3).value)
$w("#input3").value = .replace(/(\d)(?=(\d{3})+(?!\d))/g)
}
I don’t understand what the desired format is.
On one hand you said you wanted to add a point every 3 digits,
but on the other hand, your examples include points in other places: 1.111 . 111 (here it’s after the first digit), 12.345.678 (after the first 2 digits).
So what exactly is the desired format?
First you’ll need to set the user input type as text.
Then you can try this code:
$w.onReady(() => {
$w("#input1").onKeyPress(event => {
setTimeout(parseString, 10);
})
function parseString() {
let value = $w("#input1").value;
let stringDigits = value.replace(/[^0-9]/g,"");//to omit any charterer other than a digit;
if(stringDigits.length === 0){
$w("#input1").value = "";
} else {
let number = Number(stringDigits);
$w("#input1").value = number.toLocaleString('de-DE');
}
}
})
I really appreciate your collaboration but something happens, when you get to type the seventh number everything is deleted I don’t know what will be happening