i wonder how i can format automatically input value in react for the money based values.
So i want to allow this type values:
eg: if user will wan't to write;
20 - it will be 20.00 if 1000, it will be 1,000.000
I wan't to prevent any other user inputs and show error if so. How i can do it in react?
I'm using react-table so my input some editable cell. Because of it's div behave like input: I Tried this:
<div
          className="coastInput"
          contentEditable
          onBlur={e => {
            const re = /^[0-9\b,.]+$/;
            if (e.target.innerHTML == "" || re.test(e.target.innerHTML)) {
              this.setState({
                isError: false
              });
              const data = [...this.state.data];
              data[cellInfo.index][cellInfo.column.id] = e.target.innerHTML;
              this.setState({ data });
              editedData.push({
                total: this.state.data[cellInfo.index][cellInfo.column.id],
                id: cellInfo.row._original.id,
              });
            } else {
              return (
                this.setState({
                  isError: true
                }),
                alert("Just numbers allowed")
              );
            }
          }}
          dangerouslySetInnerHTML={{
            __html: this.state.data[cellInfo.index][cellInfo.column.id]
          }}
        />
