passing a varaible out of a function

passing a varaible out of a function

IPaddressPrivate  is always returned as undefined when i try to add it to the output warning. Please advise.


  1. var IPaddressPrivate;
  2.  
  3.   var localcheckIP = function(value){
  4.           var ip=value;
  5.          if(ip.length!=0){
  6.             var ipaddresses = new Array();
  7.             ipaddresses = ip.split(";");
  8.             for (var i = 0; i <ipaddresses.length; i++) {
  9.                 var sub =jQuery.trim(ipaddresses[i]);
  10.                 sub = sub.replace(/\*/g,"0-255");
  11.                 IPaddressPrivate = sub;
  12.                      var ipoctet172 = false;
  13.                      var ipoctet192 = false;
  14.                     /* These IP address are exceptions and should trigger warning message */                                     
  15.                           var parts = sub.split(".");
  16.                           if (parts[0] != null && parts[1] != null && parts[2] != null && parts[3] != null) {
  17.                           for (var j=0; j<parts.length;j++) {
  18.                               if (j == 0){
  19.                                   /*first check if ip 1st octet is 10 if 10 then must be internal IP address return ERROR message*/
  20.                                   if (parseInt(parseFloat(parts[j])) == 10) { return false;} 
  21.                                   /*next check if IP 1st octet is 172 if 172 set flag */
  22.                                    else if (parseInt(parseFloat(parts[j])) == 172) {ipoctet172 = true;}
  23.                                   /*else check if IP 1st octet is 192 if 192 set flag */
  24.                                    else if (parseInt(parseFloat(parts[j])) == 192) {ipoctet192 = true;}
  25.                               }
  26.                               if (j == 1 && ipoctet172) {
  27.                                           /* now this is the only IP range that we need to some further checking too see if there is a range */
  28.                                           var ipelement = parts[j];
  29.                                           if (ipelement.search("-") == -1) {
  30.                                             ipelement = ipelement + "-" + ipelement;
  31.                                         }
  32.                                           var octeterange =ipelement.split("-");
  33.                                           var count = 0;
  34.                                           for (var k=16; k<=31; k++) {
  35.                                               if (k >= (parseInt(parseFloat(octeterange[0])))  &&  (k <= (parseInt(parseFloat(octeterange[1]))))) {return false;}
  36.                                              /*count+= 1;
  37.                                              if (count == 20) {
  38.                                                  alert ("break!");
  39.                                                  break;}*/
  40.                                          }
  41.        
  42.                                    
  43.                                   } else if (j == 1 && ipoctet192) {
  44.                                       var ipelement = parts[j];
  45.                                           if (ipelement.search("-") == -1) {
  46.                                             if (parseInt(parseFloat(ipelement)) == 168) {return false;}
  47.                                         } else {
  48.                                             var octeterange = ipelement.split("-");
  49.                                             if ((168 >= parseInt(parseFloat(octeterange[0]))) && (168 <= (parseInt(parseFloat(octeterange[1]))))) {return false;}
  50.                                         }
  51.                                  
  52.                                   }
  53.                                      
  54.                                   }
  55.            
  56.                           }     
  57.            
  58.             }
  59.         }
  60.         return true;
  61.  }
  62.  IPaddressPrivateMessage = "At least one of the IP addreses specifyed are Private IP Addresses. " + IPaddressPrivate + " "
  63. $.validator.addMethod("checkIPlocal", function(value, element) {
  64.      return localcheckIP(value);
  65. },
  66. IPaddressPrivateMessage
  67. );