This RegEx Works Only For 8 Digits Phone Number, How To Make It Works For 15 Digits?
<p>Someone in Stack Overflow gave me this code:</p>

<pre><code>$output = preg_replace( '/(\+?\d{2}|0)(\d{7,8})/', '0$2', $test);
</code></pre>

<p>It changes user input:</p>

<blockquote>
  <p>+622112345 into 02112345</p>
  
  <p>622112345 into 02112345</p>
  
  <p>02112345 into 02112345</p>
</blockquote>

<p>Unfortunately it only works for 7-8 digits. I decided to change the code into this: </p>

<pre><code>$output = preg_replace( '/(\+?\d{2}|0)(\d{15})/', '0$2', $test);
</code></pre>

<p>By changing <code>(\d{7,8})</code> into <code>(\d{15})</code>, I hoped I could get this RegEx to validate up to 15 digits. But, here's what I have:</p>

<pre><code>input : 083812345678910 &gt;&gt; output : 083812345678910 [correct]

input : 6283812345678910 &gt;&gt; output : 6283812345678910 [false, should be : 083812345678910]

input : +6283812345678910 &gt;&gt; output : 6283812345678910 [false, should be : 083812345678910]
</code></pre>

<p>How can I make this works on 15 digit numbers? Thanks.</p>

<p>UPDATE : user input can be 10, 11, 12 or even 13 digits. but not more than 15 digits. so I need this code to change the prefix : either +62, 62 or 0 INTO 0xxxx. no matter how many digits they have, 15 maximum.</p>
