title: How to allow only numbers in textbox and format as US mobile number format in react js? ex : (224) - 5623 -2365
body: <p>I am using React for mobile number validation. The TextField should allow only digits and it will format as US mobile number format. I am restricting to allow only digits, but the format is not happening. I am using material-ui for validation. Below my code.</p>
  
  <pre><code>import React from 'react';
  import TextField from '@material-ui/core/TextField';
  
  export default class myClass extends React.Component {
      constructor(props) {
          super(props);
  
          this.state = {
              value: '',
          };
          this.handleChange = this.handleChange.bind(this);
      }
      handleChange(e) {
          const re = /[0-9]+/g;
          if (e.target.value === '' || re.test(e.target.value)) {
              this.setState({ value: e.target.value });
          }
      }
      render() {
          return (
              &lt;div&gt;
                  &lt;TextField
                      floatingLabelText="mobileNumber"
                      onChange={this.handleChange}
                      value={this.state.value}
                  /&gt;
              &lt;/div&gt;
          );
      }
  }
  </code></pre>