Reputation: 15
How can I chceck on iPhone with regularexpressions NSStrring contain only this chars: a-zA-Z
numbers 0-9
or specialchars: !@#$%^&*()_+-={}[]:"|;'\<>?,./
Upvotes: 0
Views: 680
Reputation: 9973
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:@"\w[!@#$%^&*()_+-={}\[\]:\"|;'\<>?,./]"
options:NSRegularExpressionCaseInsensitive
error:&error];
NSUInteger numberOfMatches = [regex numberOfMatchesInString:string
options:0
range:NSMakeRange(0, [string length])];
Note that NSRegularExpression
is only available on iOS 4 and above.
Upvotes: 0
Reputation: 735
NSCharacterSet *charactersToRemove = [[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 "] invertedSet];
NSString *stringValueOfTextField = [[searchBar.text componentsSeparatedByCharactersInSet:charactersToRemove]
componentsJoinedByString:@""];
try this::::
Upvotes: 2