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)
}
![](https://static.wixstatic.com/media/a27d24_df86c4604ec248c7a71c48202276c6dc~mv2.png/v1/fill/w_80,h_65,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/a27d24_df86c4604ec248c7a71c48202276c6dc~mv2.png)
To this, while the user is writing:
![](https://static.wixstatic.com/media/a27d24_bfc92ad6c6ce49a7b43f7e41cc868c32~mv2.png/v1/fill/w_74,h_69,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/a27d24_bfc92ad6c6ce49a7b43f7e41cc868c32~mv2.png)
Hope you can help me, thanks.
was the text format! now is working! thanks a lot!
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
can you share me a code for the points to be added while typing please!
could you help me, I would like to write the point in thousands and millions. I tried to use this code but when I type a seventh digit, what I am writing is deleted. Thanks a lot
Thanks a lot J.D. it works for me, i put a photo with your answer in my bedroom for remember it jajaja
Have a nice day.
Anyway, if you want the point to appear every 3 digits, then:
If you want the points to be added while typing you can use this code:
$w.onReady(function () { $w("#input3").onKeyPress( (event) => { setTimeout(parseString, 10); }) function parseString() { let value = $w("#input3").value; let stringDigits = value.replace(/[^0-9]/g,""); let finalString = stringDigits.replace(/...\B/g, "$&."); $w("#input3").value = finalString; } })
If you want the points to appear only when the user gets out of the input box, you can use this code:
$w.onReady(function () { $w("#input3").onBlur( (event) => { let value = $w("#input3").value; let stringDigits = value.replace(/[^0-9]/g,""); let finalString = stringDigits.replace(/...\B/g, "$&."); $w("#input3").value = finalString; }) })
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?