title: Flutter - Validate a phone number using Regex
body: <p>In my Flutter mobile app, I am trying to validate a phone number using <code>regex</code>. Below are the conditions.</p>
  <ol>
  <li>Phone numbers must contain 10 digits.</li>
  <li>In case country code us used, it can be 12 digits.  (example country codes: +12, 012)</li>
  <li>No space or no characters allowed between digits</li>
  </ol>
  <p>In simple terms, here is are the only &quot;valid&quot; phone numbers</p>
  <p><code>0776233475</code>, <code>+94776233475</code>, <code>094776233475</code></p>
  <p>Below is what I tried, but it do not work.</p>
  <pre><code>String _phoneNumberValidator(String value) {
      Pattern pattern =
          r'/^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/';
      RegExp regex = new RegExp(pattern);
      if (!regex.hasMatch(value))
        return 'Enter Valid Phone Number';
      else
        return null;
    }
  </code></pre>
  <p>How can I solve this?</p>