How to properly format numbers on <TextInput> on the fly in React Native?
P粉396248578
P粉396248578 2023-09-11 13:24:19
0
1
548

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

The above code will not work properly.

instead of showing 214.124.124.124

It will show 2.1.4.1.2.4.1.2.4.123

No problem with regex, I tried regex outside of TextInput and it worked fine. Can anyone help me solve this problem?

P粉396248578
P粉396248578

reply all(1)
P粉724256860

There may be some problems with your regular expression. Trying to debug it, I checked via Regex101 and it showed the error.

Try reading this articleHow to format numbers to currency when using React Native Expo?

Hope this helps.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!