首页 > 代码库 > swift 手机号码正则表达式 记录一下

swift 手机号码正则表达式 记录一下

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

 

swift 手机号码正则表达式 记录一下