美文网首页
PHP正则验证大全

PHP正则验证大全

作者: 旋转哥 | 来源:发表于2017-07-29 09:27 被阅读0次


    ## 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

    ```

    ```

    相关文章

      网友评论

          本文标题:PHP正则验证大全

          本文链接:https://www.haomeiwen.com/subject/dcpqlxtx.html