PHP中常見的驗證函式

2021-08-21 14:40:17 字數 2685 閱讀 6174

class yanzhenglei

/*** 檢查ip    

* @param string $str ip位址0.0.0.0

* @return bool

*/    

public static function is_ip($str)

/*** 檢查手機    

* @param string $str 手機號碼

* @return bool

*/        

public static function is_mobile($str)[0-9]$|15[012356789][0-9]$|177[0-9]$|18[012356789][0-9]$|14[57][0-9]$/";

return preg_match($exp,$str) ? true : false;

}/**

* 檢查使用者名稱    

* @param string $str    使用者名稱

* @return bool

*/    

public static function is_username($str)$/",$str) ? true : false; 

}/**

* 檢查email    

* @param string $str email位址

* @return bool

*/    

public static function is_email($str)([\.][a-z])?/i",$str) ? true : false; 

}/**

* 檢查密碼字元

* @param string $str 密碼字元

* @return bool

*/    

public static function is_password($str , $min = 6, $max = 20),.?\/:;\'\"\d\w]$/",$str) ? true : false; 

}/**

* 檢查簡單密碼

* @param string $str 密碼字元

* @return bool

*/        

public static function is_complex_password($str , $min = 6, $max = 20)    

/*** 檢查整數(含長度)

* @param int $val 數字

* @param int $min 最小長度預設1

* @param int $max 最大長度預設20

* @return bool

*/    

public static function is_int($val, $min = 1, $max = 20) $/", $val)? true : false;

}/**

* 檢查貨幣形式

* @param number $val 數字

* @return bool

*/    

public static function is_money($val) $/", $val) )

return preg_match("/^[0-9]\.[0-9]$/", $val)? true : false;

}/**

* 檢查身份證號

* @param string $str 身份證號碼

* @return bool

*/    

public static function is_idcard($str)

[xx\d]|[\d])$/', $str)) return false;

if (!in_array(substr($str, 0, 2), $vcity)) return false;

$str = preg_replace('/[xx]$/i', 'a', $str);

$vlength = strlen($str);

if ($vlength == 18)

else

if (date('y-m-d', strtotime($vbirthday)) != $vbirthday) return false;

if ($vlength == 18)

if($vsum % 11 != 1) return false;

}return true;

}/**

* 檢查是否為空    

* @param string $str 任意待校驗的字串

* @return bool

*/    

public static function is_empty($str)  

/*** 檢查是否為允許的格式jpg png gif

* @param string $filename 檔案路徑和檔名

* @return bool

*/    

public static function is_allow_image($filename)

return true;

}      

/*** 檢查是否為允許的內容格式

* @param string $str 正文

* @return bool

*/public static function is_trash_content($str)

}

php中常見陣列函式

1,定位陣列 bool in array mixed needle,array haystack bool strict 查詢指定元素 array array keys arraqy input mixed search value 返回鍵值組成的陣列 bool array key exists m...

php開發中常見函式記錄

htmlspecialchars decode 將特殊的 html 實體轉換回普通字元 string htmlspecialchars decode string string int flags ent compat ent html401 string 要解碼的字串 flags 用下列標記中的乙...

random 函式中常見的函式

usr bin python coding utf 8 import random print random.randint 1,10 產生 1 到 10 的乙個整數型隨機數 print random.random 產生 0 到 1 之間的隨機浮點數 print random.uniform 1.1...