以檢驗(yàn)手機(jī)號碼合法性為例:
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)
}
以檢驗(yàn)手機(jī)號碼合法性為例:
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)
}