 <p>Here is your validation simplified, and with the correct operation to check the length of the id.</p> <pre><code>if(empty($number)) { $msg = '&lt;span class="error"&gt; Please enter a value&lt;/span&gt;'; } else if(!is_numeric($number)) { $msg = '&lt;span class="error"&gt; Data entered was not numeric&lt;/span&gt;'; } else if(strlen($number) != 6) { $msg = '&lt;span class="error"&gt; The number entered was not 6 digits long&lt;/span&gt;'; } else { /* Success */ } </code></pre>