In swift, I am trying to make a text field that will allow a button to be enabled, but only when the text field contains an integer. How can I do this?
IN SWIFT 4
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if textField == mobileTF{
let allowingChars = "0123456789"
let numberOnly = NSCharacterSet.init(charactersIn: allowingChars).inverted
let validString = string.rangeOfCharacter(from: numberOnly) == nil
return validString
}
return true
}