//ip格式验证
function IsValid_Ip($ip){
if (strlen($ip) == 0)
return 0;
return preg_match('/^((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1 -9]?\d))))$/', $ip)
}
//mac格式验证,两种形式的mac地址书写
function IsValid_Mac($mac){
if (strlen($mac) == 0)
return 0;
if(preg_match("/^[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}\-[A-Fa-f0-9]{1,2}$/", $mac))
{
return 1;
} else if(preg_match("/^[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}\:[A-Fa-f0-9]{1,2}$/", $mac)) {
return 2;
}
else{
return 0;
}
}
//掩码
function Mask_Judge($mask) {
if (strlen($mask) == 0 || !IsValid_Ip($mask))
return 0;
$bin_mask = (string)decbin(ip2long($mask));
$pos_0 = strpos($bin_mask,"0");
$pos_1 = strrpos($bin_mask,"1");
if($pos_0==0||$pos_0==$pos_1+1||$pos_1==31) {
return 1;
} else {
return 0;
}
}
//时间格式
function Time_Judge($date) {
if (gettype($date) == 'string') //判断字段类型,如果是字符串,时间格式00:00
{
$d = explode(":",$date);
if (count($d) != 2)
return 0;
if (!is_numeric($d[0]) || !is_numeric($d[1]))
return 0;
if (((int)$d[0]) < 0 || ((int)$d[0]) > 23)
return 0;
if (((int)$d[1]) < 0 || ((int)$d[1]) > 59)
return 0;
return 1;
}
if (strlen($date) == 0) //如果是小数形式
return 0;
$h = (int)($date*24);
$m = (int)(($date*24*60)%60);
if(strlen($h)==1) $h = '0'.$h;
if(strlen($m)==1) $m = '0'.$m;
$t = $h.':'.$m;
if(preg_match('/^((1|0?)[0-9]|2[0-3]):([0-5][0-9])$/', $t)) {
return 1;
} else {
return 0;
}
}
//验证16进制数据
$pattern = "/(0x)[0-9a-fA-F]{1,4}|[0-9a-fA-F]{1,4}(H)/i";
return preg_match($pattern, $func);
//文件路径/受限进程路径/windows文件名命名规则
function Path_Judge($data) {
$data = (string)$data;
if (strlen($data) == 0)
return 0;
$pattern = '#^[a-zA-Z]\:\\\\[^/\:\*\?\"\<\>|]*$#';
if(preg_match($pattern, $data)) {
return 1;
} else {
return 0;
}
}