就是验证一个输入,既可以是ipv4,也可以是ipv6,还可以是合法的域名
谢谢!

解决方案 »

  1.   

    //-------------------->IP地址验证--------------------   
     function i_ip(){   
         if(!ereg("^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$", $this->var_value)){   
      $this->array_errors[$this->var_key]="错误的IP地址";   
         }else{   
    //每个不大于255   
       $array_temp=preg_split("/\./",$this->var_value);   
       foreach($array_temp as $ip_value){   
         if((int)$ip_value >255)   
         $this->array_errors[$this->var_key]="错误的IP地址";   
       }   
         }   
         return true;   
     }   
      

  2.   

    //-------------------->域名验证--------------------   
     function i_domain() {    
         if(!eregi("^@([0-9a-z\-_]+\.)+[0-9a-z\-_]+$", $this->var_value))   
       $this->array_errors[$this->var_key]="错误的域名";   
         return eregi("^@([0-9a-z\-_]+\.)+[0-9a-z\-_]+$", $this->var_value);    
     }   
      

  3.   

    //-------------------->URL验证--------------------   
     function i_url(){   
         if(!eregi('^(http://|https://){1}[a-z0-9]+(\.[a-z0-9]+)+$' , $this->var_value))   
       $this->array_errors[$this->var_key]="错误的WEB地址";   
         return true;   
     }