美文网首页
Swift4.2手机号验证

Swift4.2手机号验证

作者: 阿吖嗄 | 来源:发表于2018-08-28 09:57 被阅读16次
    func isTelNumber(num:String) -> Bool
        {
            let mobile = "^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$"
            let  CM = "^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$"
            let  CU = "^1(3[0-2]|5[256]|8[56])\\d{8}$"
            let  CT = "^1((33|53|8[09])[0-9]|349)\\d{7}$"
            let regextestmobile = NSPredicate(format: "SELF MATCHES %@",mobile)
            let regextestcm = NSPredicate(format: "SELF MATCHES %@",CM )
            let regextestcu = NSPredicate(format: "SELF MATCHES %@" ,CU)
            let regextestct = NSPredicate(format: "SELF MATCHES %@" ,CT)
            if ((regextestmobile.evaluate(with: num) == true)
                || (regextestcm.evaluate(with: num)  == true)
                || (regextestct.evaluate(with: num) == true)
                || (regextestcu.evaluate(with: num) == true))
            {
                return true
            }
            else
            {
                return false
            }
        }
    

    相关文章

      网友评论

          本文标题:Swift4.2手机号验证

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