let alphANum = "Xx0123456789"
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if textField == fatherIDCell.nameTextF || textField == motherIDCell.nameTextF {
let cs = NSCharacterSet(charactersIn: alphANum).inverted
let filtered = (string.components(separatedBy: cs) as NSArray).componentsJoined(by: "")
return string == filtered
}
return true
}
【Swift】只能输入数字和字母
最新推荐文章于 2022-03-07 22:45:00 发布