About iOS text box sometimes need to limit the number of words, such as mobile phone numbers, in the Uitextfield agent simply write a judgment, in the word exceeds the limit, then want to delete the deletion, you can write in the agent, to solve
-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *)string{ if(!string. Length) { returnYES; } if(Textfield.keyboardtype = =Uikeyboardtypenumberpad) { if([stringRangeofcharacterfromset:[[nscharacterset Decimaldigitcharacterset] Invertedset]].location! =nsnotfound) { returnNO; }} nsstring*updatedtext = [Textfield.text stringbyreplacingcharactersinrange:range withstring:string]; if(Updatedtext.length > One)//4 was chosen for SSN verification { if(string. length >1) { //Basicalert (@ "", @ "This field accepts a maximum of 4 characters."); } returnNO; } returnYES;}
IOS Uitextfield Limit input words