title: Regular expression to validate New Zealand phone numbers
body: <p>I need a regular expression that works in PHP and JavaScript to validate New Zealand local, mobile and freecall (0800) phone numbers.</p>
  
  <pre><code>Matches:     (09)1234567, (021)123456, (021)1234567, (027)123456, 0800 12345, 0800 1234578
  Non-Matches: (09)123456 , (021)12345 , (031)1234567, (027)12345 , 0800-1234, 0800123456789
  </code></pre>
  
  <p>Below is a regular expression I found on the web but it does not seem to work for some reason:</p>
  
  <p>(^([0]\d{1}))(\d{7}$)|(^([0][2]\d{1}))(\d{6,8}$)|([0][8][0][0])([\s])(\d{5,8}$)</p>
  
  <p>Can someone please help with the expression above? Thank you for your help in advance.</p>
  
  <p><strong>UPDATE - I worked it out and the solution is below:</strong></p>
  
  <pre><code>$phone_number = preg_replace('/[^\d\(\)]/', '', $phone_number);
  $pattern = '/^(\((03|04|06|07|09)\)\d{7})|(\((021|022|025|027|028|029)\)\d{6,8})|((0508|0800|0900)\d{5,8})$/';
  </code></pre>