TP邮箱、手机号、特殊字符验证

作者: adm 分类: php 发布时间: 2023-03-12
$phone = $this->isInvalidPhone($param['phone']);
if(!$phone){
    ReturnAjax([], '手机号格式错误', 2001);
}
// 验证邮箱
    public function isInvalidEmail($string) {
        // $string = "13456@qq.com";
        if (preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/",$string)) {
            return true;
        } else {
            return false;
        }
    }
    // 验证手机号
    public function isInvalidPhone($string) {
        // $string = "13456@qq.com";
        if (preg_match("/^1\d{10}$/",$string)) {
            return true;
        } else {
            return false;
        }
    }

    // 验证特殊字符
    public function isInvalidStr($string) {
        // $string = "13456@qq.com";
        if (preg_match("/\/|\~|\,|\。|\!|\?|\“|\”|\【|\】|\『|\』|\:|\;|\《|\》|\’|\‘|\ |\·|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\:|\<|\>|\?|\[|\]|\,|\.|\/|\;|\'|\`|\-|\=|\\\|\|/",$string)) {
            return true;
        } else {
            return false;
        }
    }


    // 验证表情
    public function isInvalidEmoji($string){
        if (preg_match("/[\x{4e00}-\x{9fff}\d\w\s[:punct:]]+/u",$string)) {
            return true;
        } else {
            return false;
        }
    }

如果觉得我的文章对您有用,请随意赞赏。您的支持将鼓励我继续创作!