Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Jose Ines Cantu Arrambide
43 PointsIs there a lesson on constricting a UITextField to positive numbers only ?
Any lesson on forcing a UITextField to accept only positive numbers? With a minimum and maximum ?
2 Answers
Jose Ines Cantu Arrambide
43 PointsRichard thank you for your reply :) Do you know what delegate method would be the best to validate the minimum and maximum values of the UITextField ?
Richard Lu
20,185 PointsHey Jose,
From what I understand you want a UITextField to only accept numbers that are positive. I'm not sure if this is a way that you would want to go about it, but you can change the keyboard type to a numberpad like this
someTextField.keyboardType = UIKeyboardType.NumberPad
This would result in only accepting positive numbers.
If this isn't what you're looking for, I'd suggest searching for customized keyboards.
edit:
As for having a maximum and minimum, I'd check the input in the textfieldDelegate method textFieldDidEndEditing:.
Good luck! :)

Richard Lu
20,185 PointsRichard Lu
20,185 PointsHey Jose,
This delegate method should work: