把以前oc时候写的一些正则用swift 写了下来。
///字符串
var sStr :String = "^\\w{2}$"
let sText :NSPredicate = NSPredicate.init(format: "SELF MATCHES %@", sStr)
let sValue = sText.evaluateWithObject("ab")
///邮箱
var emailStr :String = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"
let emailText :NSPredicate = NSPredicate.init(format: "SELF MATCHES %@", emailStr)
let value = emailText.evaluateWithObject("gsn.1125@163.com")
///固定电话
var telStr :String = "^(0[0-9]{2,3}\\-)?([0-9][0-9]{6,7})+(\\-[0-9]{1,4})?$"
let telText :NSPredicate = NSPredicate.init(format: "SELF MATCHES %@", telStr)
let telValue = telText.evaluateWithObject("010-1234678")
///手机号
var phoneStr :String = "^1[3,5,6,7,8][0-9]\\d{8}"
let phoneText :NSPredi