我试图让它成为一个UITexField,当它被一个方法检查时返回false,如果它有除了字母之外的任何东西,我试图创建一个RegEx,但是还没能让它工作
func checkNames(name: UITextField, text: UILabel) -> Bool {
let regEx = "[,./-=+}{[]`~'!@£$%^&*():;?0-9]"
let regExTest = Predicate(format:"SELF MATCHES %@", regEx)
let charResult = regExTest.evaluate(with: name.text)
if name.text != nil && charResult == false {
text.textColor = UIColor(red: 124, green: 252, blue: 0)
return true
} else {
text.textColor = UIColor(red: 255, green: 0, blue: 0)
name.text = nil
name.placeholder = "Alphabetical Name Required"
return false
}
}
如果它只有字母,我希望它返回false。