我必须检查id是否有效,才能在系统中注册用户。为了做到这一点,我一直在阅读有关NSPredicate类的文章。
但是,我不知道如何构建下一个模式:
有效的id必须由8个数字和最后一个字母组成。有人能帮我吗?
谢谢
发布于 2010-11-22 03:04:37
尝试这个(未测试):
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.
}
https://stackoverflow.com/questions/4239599
复制相似问题