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.
Is there any way to restrict user to enter only numeric values in a UITextField
?
Note: This is an old question with many many answers. More than one third of the posted answers are wrong. Even some of the highly upvoted answers are wrong. Please, DO NOT post a new answer unless it somehow finds a vastly improved way to solve this question in a way that isn't shown already. Make sure your answer works in all circumstances. It must work for both iPhones and iPads. It must work when a user pastes text into the text field. It must work if the user has an external keyboard. It must work if the user changes the text selection in the text field before typing or pasting text. It must properly support decimal numbers (one decimal separator appropriate for the user's locale).