I\'ve got a string that needs to be only a-z, 0-9 and _
How do I check if the input is valid? I\'ve tried this but it accepts letter like å,ä,ö,ø etc.
NS
You can use a predicate:
NSString *myRegex = @"[A-Z0-9a-z_]*";
NSPredicate *myTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", myRegex];
NSString *string = nameField.text;
BOOL valid = [myTest evaluateWithObject:string];
Edit:
I don't noticed that you are using [NSString stringWithString:nameField.text]
.
Use nameField.text
instead.