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
NSString*dogswithMotionSickness=motionSicknessTextField.text;
NSString*valueOne=cereniaTextField.text;
NSString*valueTwo=prescriptionTextField.text;
NSString*valueThree=otherMeansTextField.text;
NSString*valueFour=overtheCounterTextField.text;
In whatever UITextField you’re getting these values from, you can specify the kind of keyboard you want to appear when somebody touches inside the text field.
E.G. a numeric-only keyboard.
Like this screenshot:
This is easily set when working with the XIB and the Interface Builder built into Xcode, but if you want to understand this programmatically, take a look at Apple’s
UITextInputTraitsprotocol reference page, specifically thekeyboardTypeproperty information.To filter out punctuations, set the textfield’s delegate and set up the shouldChangeCharactersInRange method: