码迷,mamicode.com
首页 > 移动开发 > 详细

Swift中用正规表达式判断String是否是手机号码

时间:2016-02-23 15:56:51      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:

func isTelNumber(num:NSString)->Bool
{
    var mobile = "^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$"
    var  CM = "^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$"
    var  CU = "^1(3[0-2]|5[256]|8[56])\\d{8}$"
    var  CT = "^1((33|53|8[09])[0-9]|349)\\d{7}$"
    var regextestmobile = NSPredicate(format: "SELF MATCHES %@",mobile)
    var regextestcm = NSPredicate(format: "SELF MATCHES %@",CM )
    var regextestcu = NSPredicate(format: "SELF MATCHES %@" ,CU)
    var regextestct = NSPredicate(format: "SELF MATCHES %@" ,CT)
    if ((regextestmobile.evaluateWithObject(num) == true)
        || (regextestcm.evaluateWithObject(num)  == true)
        || (regextestct.evaluateWithObject(num) == true)
        || (regextestcu.evaluateWithObject(num) == true))
    {
        return true
    }
    else
    {
        return false
    }  
}

  引用:http://www.jianshu.com/p/734bf1464489

Swift中用正规表达式判断String是否是手机号码

标签:

原文地址:http://www.cnblogs.com/yesicoo/p/5210072.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!