Iphone: NSPredicate in order to check an id
i have to check if an id is valid to register an user in the system. I have been reading about the 开发者_Python百科class NSPredicate in order to do this.
However, i don't know how to build the next pattern:
A valid id has to be composed by 8 numbers and one final letter. Can anyone help me with that?
Thanks
Try this out (untested):
NSString *stringID = ...; // get the id
NSString *regex = @"[0-9]{8}[A-Za-z]";
NSPredicate *rp = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if ([rp evaluateWithObject:stringID]) {
// ID is valid!!
} else {
// ID is not valid.
}
精彩评论