PHP正則驗證類

2021-09-07 04:43:49 字數 3422 閱讀 5875

<?php/**

* 驗證類

* * @lastmodify 2015-12-19

* @author wuheng */

class

verify

/*** 數字驗證

* param:$flag : int是否是整數,float是否是浮點型

*/public

static

function isnum($str,$flag = 'float')

else

} /**

* 名稱匹配,如使用者名稱,目錄名等

* @param:string $str 要匹配的字串

* @param:$chinese 是否支援中文,預設支援,如果是匹配檔名,建議關閉此項(false)

* @param:$charset 編碼(預設utf-8,支援gb2312)

*/public

static

function isname($str,$chinese = true,$charset = 'utf-8')-xa-za-z0-9_]+$/u";

}else

return

preg_match($match,$str) ? true : false

; }

/*** 郵箱驗證

*/public

static

function isemail($str

)([\.][a-z])?/i",$str) ? true : false

; }

//手機號碼驗證

public

static

function ismobile($str

)$/";

if(preg_match($exp,$str

))else

}/**

* url驗證,純**格式,不支援ip驗證

*/public

static

function isurl($str

) /**

* 驗證中文

* @param:string $str 要匹配的字串

* @param:$charset 編碼(預設utf-8,支援gb2312)

*/public

static

function ischinese($str,$charset = 'utf-8')-x]+$/u";

return

preg_match($match,$str) ? true : false

;

}/**

* utf-8驗證

*/public

static

function isutf8($str

)[".chr(128)."-".chr(191)."][".chr(128)."-".chr(191)."])/",$word

) == true || preg_match("/([".chr(228)."-".chr(233)."][".chr(128)."-".chr(191)."][".chr(128)."-".chr(191)."])$/",$word

) == true || preg_match("/([".chr(228)."-".chr(233)."][".chr(128)."-".chr(191)."][".chr(128)."-".chr(191)."])/",$word

) == true) ? true : false

; }

/*** 驗證長度

* @param: string $str

* @param: int $type(方式,預設min <= $str <= max)

* @param: int $min,最小值;$max,最大值;

* @param: string $charset 字元

*/public

static

function length($str,$type=3,$min=0,$max=0,$charset = 'utf-8')

}/**

* 驗證密碼

* @param string $value

* @param int $length

* @return boolean

*/public

static

function ispwd($value,$minlen=6,$maxlen=16)\[\],.?\/:;\'\"\d\w]$/';

$v = trim($value

);

if(empty($v

))

return

false

;

return

preg_match($match,$v

); }

/*** 驗證使用者名稱

* @param string $value

* @param int $length

* @return boolean

*/public

static

function isnames($value, $minlen=2, $maxlen=16, $charset='all')$/iu';

break

;

case 'cn':$match = '/^[_\x-\x\d]$/iu';

break

;

default:$match = '/^[_\w\d\x-\x]$/iu';

}return

preg_match($match,$value

); }

/*** 驗證郵箱

* @param string $value

*/public

static

function checkzip($str

)

if(substr($str,0,1)==0)

return

true

; }

/*** 匹配日期

* @param string $value

*/public

static

function

checkdate($str

)

return

false

; }

/*** 匹配時間

* @param string $value

*/public

static

function checktime($str

)

return

false

; } }

PHP常用正則驗證

手機號,身份證,ip驗證 正則驗證手機號 正確返回 true function preg mobile mobile mobile else 驗證 號碼 function preg tel tel d d tel else 驗證身份證號 15位或18位數字 function preg idcard ...

PHP常用正則驗證

手機號,身份證,ip驗證 正則驗證手機號 正確返回 true function preg mobile mobile mobile else 驗證 號碼 function preg tel tel d d tel else 驗證身份證號 15位或18位數字 function preg idcard ...

PHP驗證ip email host不用正規表示式

最近在使用php的過程中,發現了乙個特別好用的內建函式,用來驗證輸入資料的格式的,相對於自己寫正規表示式來說,方便了不少,只要乙個函式既可以搞定,我們來看一下 要說的這個函式就是filter var 具體的用法如下 如果您要驗證某個字元是否是email filter var email,filter...