常用正则

1、手机号码:/^[1][34578][0-9]{9}$/
2、用户姓名:/^[a-zA-Z0-9\x{4e00}-\x{9fa5}]+$|^[a-zA-Z0-9\x{4e00}-\x{9fa5}][a-zA-Z0-9_\s\ \x{4e00}-\x{9fa5}\.]*[a-zA-Z0-9\x{4e00}-\x{9fa5}]+$/u

3、php以四位,空格补填: 

    //处理卡号的显示
    protected function cardFormat($card_num){
        $count = floor(strlen($card_num)/4);
        $patten = '/'.str_repeat('([\w]{4})',$count).'([\w]{0,})?/';
        preg_match($patten, $card_num,$match);
        unset($match[0]);
        return implode(' ', $match);
    }

 

posted @ 2018-04-04 18:07  岁月静好13543  阅读(166)  评论(0编辑  收藏  举报
AmazingCounters.com