Question

<div>
   <TextField
      value={this.state.Budget}
      onChanged={this.onChangeBudget}
   />
</div> 

public onChangeBudget = (value: string) => {
   console.log("Budget : " + value);
   console.log(value.replace(/\B(?=(\d{3})+(?!\d))/g, ','));
   let abc = value.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
   return this.setState({ Budget: abc });
}

So the issue is when I am logging the value its showing correct result(1,111,111,111). But when I am doing the setState for the same, it is shows the result like this (1,1,1,1,1,1,1,1,111).

Please suggest where am I going wrong?

No correct solution

OTHER TIPS

My test code for your reference:

public onChangeBudget = (value: string) => {
    
    let newValue=value.replace(/,/g, "");
   
    let abc = newValue.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
    return this.setState({ Budget: abc });
 }

Test result: enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top