0
<TextInput value={initialMoney} 
    onChangeText={(x) => {
      setInitialMoney(x.replace(/\B(?=(\d{3})+(?!\d))/g, '.'));
    }}
/>

The above code will not work correctly.

Instead of displaying 214.124.124.124

It will display 2.1.4.1.2.4.1.2.4.123

There is nothing wrong with the Regular Expression, I tried the regex outside the TextInput, and it works perfectly. Can anyone help me with this?

1 Answers1

0

There might be some issues with your Regex. Try debugging it, I checked via Regex101 and it showed errors. enter image description here

Try reading this post How do you format a number to currency when using React native Expo?

Hope this helps.