I have a TextField in xCode and someone ask me to admit just certain types of characters giving me this text string:
^([A-ZÑÑÁÉÍÓÚÀÈÌÒÙÄËÏÖÜ ])*$
or this one:
^([0-9])*$
I Know a method using UITextFieldDelegate named textField shouldChangeCharactersInRange and this is the way I implement this method:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString *allowedCharacters = @"abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMÑNOPQRSTUVWXYZ0123456789.@-_ ";
NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:allowedCharacters];
if ([string stringByTrimmingCharactersInSet:characterSet].length == 0)textField.text = [textField.text stringByReplacingCharactersInRange:range withString:string];
return NO;
return YES;
}
if you see, on my programming my variable allowedCharacters stores all my valid characters but is in a different format (I have to write all the allowed characters),
I want to program something similar but with my partner's text format ^([0-9])*$ (text using ranges) how do I do that
Thanks in advance