Using just regular expression, you can have a method like this:
- (BOOL)validarCampo {
NSString *string = [self.campoQualquer text];
NSRange range = [string rangeOfString:@"^\d{6}(SP|MG|RJ)$" options:NSRegularExpressionSearch];
if (range.location == NSNotFound) {
return NO;
}
return YES;
}
It would be extended there where you complete with the rest of the acronyms of all the states.
Otherwise, for this validation of states you can have a NSArray
simple and then validate out the last two characters. But this way with regular expression already works the way you need it.