The iPad does not have a “Numpad” keyboard like the iPhone/iPod does.
I’m looking to find how I can restrict the user’s keyboard to only accept values 0 through 9.
I would imagine using UITextField’s “shouldChangeCharactersInRange” but I don’t know the best way to implement it.
This is how you might handle the problem on a SSN verification field, you can modify the max length and remove the
ifstatement checking for keyboard type if you need to.There is also logic to suppress the max length alerts when the user is typing as opposed to pasting data.
Within the context of this code,
presentAlert()/presentAlert:is just some basic function that presents aUIAlertController(or a legacyUIAlertView) using the message string passed.Swift 5
Objective-C