PHP正則驗證大全



## PHP

```

/*驗證手機號*/

function is_mobile($str){

return preg_math('/^1[34578]{1}\d{9}$/',$str)?true:false;//13 347106430

}

/*驗證郵箱號*/

function isEmail($str)

{

return filter_var($str,FILTER_VALIDATE_EMAIL);

}

/*驗證微信號*/

function isWeixinid($str)

{

return preg_match('/^[\w-]{4,20}/', $str) !== 0;

}

/*驗證密碼*/

function verifypasswd($str, $min = 6, $max = 32, $minType = 2)

{

$len = strlen($str);

if ($len < $min || $len > $max) {

return false;

}

$score = 0;

if (preg_match("/\d/", $str))

$score++;

if (preg_match("/[a-z]/", $str))

$score++;

if (preg_match("/[A-Z]/", $str))

$score++;

if (preg_match("/\W/", $str))

$score++;

return $score >= $minType;

}

/*產(chǎn)生字符串*/

function getRandChar($length,$mode = 0)

{

$str = '';

switch ($mode) {

case 3:

$strPol = "123456789";

break;

default:

$strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";

break;

}

$max = strlen($strPol) - 1;

while ($length--) {

$str .= $strPol[mt_rand(0, $max)];

}

return $str;

}

```

## Javascript

```

```

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容