I have UITexfields i want that it should accept only number other shows alert that enter a numeric value. I want that motionSicknessTextFiled should only accept number
Here is the working example for swift 4
public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool
{
// Allow Backspace
if string.count == 0 {
return true
}
// Allow Only Valid Decimal Numbers
if let textFieldText = textField.text {
let finalText = (textFieldText as NSString).replacingCharacters(in: range, with: string)
if Double(finalText) != nil {
return true
}
}
return false
}