2

I have made currency input mask:

      let resultArr = value.split("").map((x) => {
        return !isNaN(+x) && x !== " " ? "n" : "";
      });
      resultArr = resultArr.join("").replace(/\B(?=([n]{3})+(?![n]))/g, ","); //1234 => nnnn, 1234 => 123,4
      return "$" + `${resultArr}\rn`;

where value is the value of input (https://codesandbox.io/s/suspicious-currying-68cl8?file=/index.js), but there is the error Maximum update depth exceeded. I find out that's because of \r code in my input mask. How can I fix this error?

Pavel
  • 37
  • 1
  • 8
  • hi, you should add the part of code that made error, it's better to embed the code in your question – Ali Feb 02 '21 at 12:19
  • It's done, see update @Ali – Pavel Feb 02 '21 at 12:36
  • i think it's because of your regex, maybe it's ok : \d{1,3}(?=(\d{3})+(?!\d)) acording to https://stackoverflow.com/questions/721304/insert-commas-into-number-string – Ali Feb 02 '21 at 12:53
  • It's definately not because of regex, I think its because my input has 1 line and cannot move with \r @Ali – Pavel Feb 02 '21 at 12:56
  • I have tried and its the same error – Pavel Feb 02 '21 at 12:57

0 Answers0