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;

}

/*产生字符串*/

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

```

```

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容