I want the user to only enter numeric values in a UITextField
. On iPhone we can show the numeric keyboard, but on iPad the user can switch to any keyboard.
Set KeyboardType Property :- Number Pad TextField Delegate please write below code
func textField(_ textField: UITextField, shouldChangeCharactersIn
range: NSRange, replacementString string: String) -> Bool {
if textField.text?.count == 0 && string == "0" {
return false
}
return string == string.filter("0123456789".contains)
}
Number should not start from 0 and entered number +ve.