Try to validate IP Address with javascript
<p>I'm a beginner to javascript. Now, I'm trying to make a form to post back to server. There are some "input" that contains ip address which should be validate before submitting. Now I have done a javascript function which work well. But now I'm trying to add this function into jquery selection. Just confuse how to do it.</p>

<p>This is my validate javascript code.</p>

<pre><code>function ValidateIPaddress(Ipfield)  
 {  
    IpAddr=Ipfield.value;
    var ipformat = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;  

    if(!IpAddr.match(ipformat))  
        return true;  
    else
        return false;

 }
</code></pre>

<p>and this is now how I implement for this validation.</p>

<pre><code>&lt;input type= "text" name= "LocalIP" style= "margin-right:10px " value="192.168.1.193" class="ip" onfocusout="ValidateIPaddress(document.getElementById('LocalIp'))" id="LocalIp" &gt;            Remote VIP Address :             
                &lt;input type= "text" name= "RemoteVIPAddr" style= "margin-right:10px" value="234.5.6.7" class="ip"  onfocusout="ValidateIPaddress(document.getElementById('RemoteIp'))" id="RemoteIp" &gt;
                Remote VIP Port :             
                &lt;input type= "text" name= "RemoteVIPPort" style= "margin-right:10px" value="5004" class="ip"  onfocusout="ValidatePort(document.getElementById('RemoteVIPPort'))" id="RemoteVIPPort"&gt;
</code></pre>

<p>Now I want to use jquery selection to always check if there are some invalid input. Which is something like this but with my own design function.</p>

<pre><code>$("input.ip:visible").filter(function() { return this.ValidateIPaddress === true }).addClass("invalid");
</code></pre>

<p>Anyone has idea bout it?</p>