'Regex for adding thousand separator WITHOUT decimals? [duplicate]

I need a regular expression for adding a dot as a thousand and millon separator in Javascript. I've searched the whole web without finding the format I need. It would return this:

1
12
123
1.234
12.345
123.456
1.234.567
12.345.678
123.456.789

I'm trying to use it in an input.

  handleIdChange = (personalIdNumber) => {
this.validator.updateField("personalId", {
  number: personalIdNumber
})
this.props.setVisitorField({
  field: "personalId.number",
  value: personalIdNumber
});

            <CLTextInput
            highContrast={true}
            onChangeText={this.handleIdChange}
            keyboardType="numeric"
            placeholder="Número"
            returnKeyType="next"
            autoCapitalize="none"
            autoCorrect={false}
            value={visitor.personalId.number}
            error={this.shouldShowError("personalId")}
            accessibility
            />


Solution 1:[1]

Don't use regular expressions to format numbers. Use a proper number formatter.

If you want german-style number formatting, set that as the locale.

const formatter = new Intl.NumberFormat('de-DE');
for (let i = 0; i < 10; i++) {
    const number = 10 ** i;
    console.log(formatter.format(number));
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Quentin