How to filter the input box by entering only letters and numbers 1.
Uitextfielddelegate protocol.
2. Define the following variables in the header file:
// Restrict the user to only letters and numbers
# Define kalphanum @ "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789"
3. In the implementation file:
Set the delegate of the textfiled object to self:
M_accountfield = [[uitextfield
Alloc] initwithframe: cgrectmake (89,
26,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 {nscharacterset * cs; cs = [[nscharacterset limit: kalphanum] invertedset]; nsstring * filtered = [String componentsseparatedbycharactersinset: CS] componentsjoinedbystring: @ ""]; bool basic = [String isequaltostring: Filtered]; return basic ;}