Regular expression for validating the IP Address using Javascript?

Views: 198
Created Date: 12-Sep-2016

function isValidIPAddress(ipaddr) 
 {
     var re = /^\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,3}$/;
     if (re.test(ipaddr)) 
     {
         var parts = ipaddr.split(".");
         if (parseInt(parseFloat(parts[0])) == 0) 
         {
             return false; 
         }
         for (var i=0; i<parts.length; i++)
         {
             if (parseInt(parseFloat(parts)) > 255) 
             { 
                 return false;
             }
         }
         return true;
     } 
     else 
     {
         return false;
     }
 }

Similar Tags
0.0 0