How to detect space, and special characters like:?,?, ~, Etc, in the text of a text field in iPhone SDK?

advertisements

How to detect space, and special characters like :, ?,`,~, etc in text of a textfield in iPhone SDK?


Try this..

NSCharacterSet* symbols = [NSCharacterSet symbolCharacterSet];
   if([symbols characterIsMember: yourCharacter]) {
        //Check Your condition here
    }

If you want to include many characters Use a combined NSCharacterset with NSMutableCharacterSet..

    NSMutableCharacterSet *space = [NSMutableCharacterSet characterSetWithCharactersInString:@" "];
    [space formUnionWithCharacterSet:[NSCharacterSet symbolCharacterSet]];

Use the space characterset to check the character