title: Number formatting using regex with special characters
body: <p>I am learning regex and I want to implement this in react app so when I write something on input field I want to allow user to write only numbers and maximum one space. This string also must starts with <strong>+</strong> character. My regex tool shows me good result but in app I cannot write anything.</p>
  
  <pre><code>const handlePhone = ({currentTarget}) =&gt; {
      let val = currentTarget.value;
      // Regular expression
      const reg = /^\+\d+/g;
      const isNumber = val.match(reg);
      if (isNumber || val === '') {
        setFieldValue('phone', val);
      }
    };
  </code></pre>
  
  <p>With this expression I wanted to implement this: starts with + and later you can write some digits. </p>
  
  <p><a href="https://i.stack.imgur.com/sYiYX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sYiYX.png" alt="enter image description here"></a></p>
  
  <p>But in app I cannot write anything. Why this tool is so different from this live matching? </p>
  
  <p>With this:</p>
  
  <pre><code>const reg = /^\+\d+( \d+)*$/;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/0Dn3y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0Dn3y.png" alt="enter image description here"></a></p>