Reputation: 5515
I am using a UITextField
for users to enter usernames, and would like to restrict special characters except for periods and underscores. I was initially set on using the solution from this SO question, until I realized that I do not want to restrict to only alpha-numeric characters, but also allow Asian and Middle Eastern languages characters as well. Is there a way that I would be able to accomplish this?
Thanks!
Update:
Per rmaddy's suggestion, here is what I am presently using:
- (BOOL)userNameIsAcceptable: (NSString *)userNameInputted
{
NSCharacterSet *userNameAcceptedInput = [[NSCharacterSet alphanumericCharacterSet] invertedSet];
NSString *filteredUserName = [[userNameInputted componentsSeparatedByCharactersInSet:userNameAcceptedInput] componentsJoinedByString:@""];
NSLog(@"The filtered result %@", filteredUserName);
return [userNameAcceptedInput isEqual:filteredUserName];
}
Upvotes: 0
Views: 184
Reputation: 1020
Maybe testing unicode chars from strings manually in loop against ranges containing unicode sets you need? I did quick check, and it seems that unicode sets of Japanese letters are usually densely packed, except some special characters - I've looked here http://www.rikai.com/library/kanjitables/kanji_codes.unicode.shtml but I guess similar should be valid to other languages as well.
Upvotes: 0
Reputation: 318884
Use the solution from the other question but instead of building the character set from the fixed letters, use the standard NSCharacterSet alphanumericCharacterSet
.
Upvotes: 2