Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

priyank.ranka

macrumors member
Original poster
Jun 11, 2008
51
0
Hi EveryOne,
I want to limit user from typing characters above certain limit. Suppose i want only ten character long word input from user via TextField and if user tries to input more than ten characters into the TextField the TextField cursor should not move. Any help be appreciated. Thanks for ur help.
 
Look at UITextFieldDelegate shouldChangeCharactersInRange

Return false if you don't want the characters to be entered.
 
Hi EveryOne,
I want to limit user from typing characters above certain limit. Suppose i want only ten character long word input from user via TextField and if user tries to input more than ten characters into the TextField the TextField cursor should not move. Any help be appreciated. Thanks for ur help.

Something like:

Code:
if (textField.text.length > 10) textField.text = [textField.text substringToIndex:10];

should do the trick.


EDIT: Never mind, Pring's solution is much cleaner :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.