Reputation: 5830
i have to check if an id is valid to register an user in the system. I have been reading about the 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
Upvotes: 1
Views: 396
Reputation: 3060
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.
}
Upvotes: 2