title: What is the best way of validating an IP Address?
body: <p>I have a method to validate a parameter IP Address. Being new to development as a whole I would like to know if there is a better way of doing this.</p>
  <pre class="lang-cs prettyprint-override"><code>/// &lt;summary&gt;
  /// Check IP Address, will accept 0.0.0.0 as a valid IP
  /// &lt;/summary&gt;
  /// &lt;param name=&quot;strIP&quot;&gt;&lt;/param&gt;
  /// &lt;returns&gt;&lt;/returns&gt;
  public bool CheckIPValid(string strIP)
  {
      //  Split string by &quot;.&quot;, check that array length is 3
      char chrFullStop = '.';
      string[] arrOctets = strIP.Split(chrFullStop);
      if (arrOctets.Length != 4)
      {
          return false;
      }
      //  Check each substring checking that the int value is less than 255 and that is char[] length is !&gt; 2
      Int16 MAXVALUE = 255;
      Int32 temp; // Parse returns Int32
      foreach (string strOctet in arrOctets)
      {
          if (strOctet.Length &gt; 3)
          {
              return false;
          }
  
          temp = int.Parse(strOctet);
          if (temp &gt; MAXVALUE)
          {
              return false;
          }
      }
      return true;
  }
  </code></pre>
  <p>Its simple (I could do it) but it seems to do the trick.</p>