php判断正则_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

```

```

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值