troubleshooting Question

Javascript validation not working on every field

Avatar of skinsfan99
skinsfan99Flag for United States of America asked on
JavaScriptASPHTML
5 Comments1 Solution359 ViewsLast Modified:
The code below is a section of a webpage that validates IP Addresses.  The code is only checking the first text box on each record.  Any ideas why it is not checking all text boxes?

Thanks,
David


<html>
<head>

<script type="text/javascript">
<!--
 
         var octet = '(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])';
        var ip    = '(?:' + octet + '\\.){3}' + octet;
        var ipRE  = new RegExp( '^' + ip + '$' );

        function check_ip_format( ip_field, ip_value ) {
                alert("ip_field=>>" + ip_field.name + "<<");
              alert("ip_value=>>" + ip_value + "<<");
              if (!isBlank(ip_value)){
                    alert( ( ipRE.test( ip_value ) ? '' : 'in' ) + 'valid' );
              
                    if ( !ipRE.test( ip_value ) )
                          ip_field.focus();
              }
        }

    function isBlank(val)
    {
        if (val == null) { return true; }
        for (var i = 0; i < val.length; i++) {
            if ((val.charAt(i) != ' ') && (val.charAt(i) != "\t") && (val.charAt(i) != "\n") && (val.charAt(i) != "\r")) { return false; }
        }
        return true;
    }
      
//-->
</script>
<title>Users</title>
      <link href="includes/css/main.css" rel="stylesheet">
</head>
<body onload="IPMin_1.focus();">
<table cellpadding="0" cellspacing="0" border="0" align="left" width="100%">      

      <form action="" name="form" method="post">

      <tr><td>&nbsp;</td></tr>
      <tr>
            <td>
                                    <table border="0" cellspacing="3" cellpadding="0" width="855">
                                          <tr>
                                                <td colspan="5"><hr /></td>
                                          </tr>
                                          <tr><td colspan="2">&nbsp;</td></tr>

                                          <tr>
                                                <td colspan="2">
                                                      <table cellpadding="0" cellspacing="0" border="0" width="100%">
                                                            <tr>
                                                                <td class="listheader" width="5%"><b>Record</b></td>      
                                                                <td class="listheader" width="2%">&nbsp;</td>
                                                                <td class="listheader" width="20%"><b>IP Address Minimum</b></td>
                                                                <td class="listheader" width="2%">&nbsp;</td>                                          
                                                                <td class="listheader" width="20%"><b>IP Address Maximum</b></td>      
                                                                <td class="listheader" width="2%">&nbsp;</td>
                                                            </tr>
                                                            <tr>
                                                                <td colspan="6"><hr /></td>
                                                            </tr>

                                                          <tr>
                                                                <td class="formlabel" width="5%">1</td>
                                                          <td class="listheader" width="2%">&nbsp;</td>
                                                                <td nowrap class="formdata" width="20%">
                                                                    <input class="formdata" name="IPMin_1" type="text" size="20" maxlength="25" value="98.191.209.200" onblur="javascript: return check_ip_format(IPMin_1, IPMin_1.value);" />
                                                                </td>
                                                          <td class="listheader" width="2%">&nbsp;</td>
                                                                <td nowrap class="formdata" width="20%">
                                                                      <input class="formdata" name="IPMax_1" type="text" size="20" maxlength="25" value="98.191.209.250" onblur="javascript: return check_ip_format(IPMax_1, IPMax_1.value);" />
                                                                </td>
                                                          </tr>
                               
                                                          <tr>
                                                                <td class="formlabel" width="5%">2</td>
                                                          <td class="listheader" width="2%">&nbsp;</td>
                                                                <td nowrap class="formdata" width="20%">
                                                                    <input class="formdata" name="IPMin_2" type="text" size="20" maxlength="25" value="98.191.209.199" onblur="javascript: return check_ip_format(IPMin_2, IPMin_2.value);" />
                                                                </td>
                                                          <td class="listheader" width="2%">&nbsp;</td>
                                                                <td nowrap class="formdata" width="20%">
                                                                      <input class="formdata" name="IPMax_2" type="text" size="20" maxlength="25" value="98.191.209.255" onblur="javascript: return check_ip_format(IPMax_2, IPMax_2.value);" />
                                                                </td>
                                                          </tr>
                               
                                                            <tr><td colspan="5">&nbsp;</td></tr>
                                                            <tr><td colspan="5">&nbsp;</td></tr>
                                                      </table>
                                                </td>
                                          </tr>
                                    </table>
            </td>
      </tr>                        

      </form>
</table>

</body>
</html>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros