前端之家收集整理的这篇文章主要介绍了
正则判断是否是电话号Swift,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
extension String {
func isTelNumber() -> 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.evaluateWithObject(self) == true)
|| (regextestcm.evaluateWithObject(self) == true)
|| (regextestct.evaluateWithObject(self) == true)
|| (regextestcu.evaluateWithObject(self) == true))
{
return true
}
else
{
return false
}
}
}