以检验手机号码合法性为例:
func isValidatePhoneNumber(phoneNum: String) ->Bool {
let regex: String="^1[3|5|7|8|][0-9]{9}$"
let test: NSPredicate=NSPredicate(format: "SELF MATCHES %@", regex)
return test.evaluateWithObject(phoneNum)
}
以检验手机号码合法性为例:
func isValidatePhoneNumber(phoneNum: String) ->Bool {
let regex: String="^1[3|5|7|8|][0-9]{9}$"
let test: NSPredicate=NSPredicate(format: "SELF MATCHES %@", regex)
return test.evaluateWithObject(phoneNum)
}