How can I limit the number of words in the textField input box while only entering numbers and letters 1?
UITextFieldDelegate protocol.
2. Define the following variables in the header file:
// Maximum number of account characters
# Define ACCOUNT_MAX_CHARS 16
3. In the implementation file:
Set the delegate of the textFiled object to self:
M_accountField = [[UITextField alloc] initWithFrame: CGRectMake (243, 33)];
M_accountField.borderStyle = UITextBorderStyleNone;
M_accountField.font = fieldFont;
M_accountField.delegate = self;
// Uitextfielddelegate-(bool) textfieldshouldreturn :( uitextfield *) textfield; {// user end input [textfield resignfirstresponder]; return yes;}-(bool) textfield :( uitextfield *) textfield shouldchangecharactersinrange :( nsange) range replacementstring :( nsstring *) string // return no to not change text {// determine whether to exceed account_max_chars characters. Be sure to judge the string. leng> 0 //, if it is deleted, String. length = 0 int length = textfield. text. length; If (length> = account_max_chars & string. length> 0) {return no;} nscharacterset * cs; cs = [[nscharacterset encoding: kalphanum] invertedset]; nsstring * filtered = [[String encoding: CS] componentsjoinedbystring: @ ""]; bool basic = [String isequaltostring: Filtered]; return basic ;}