//邮箱
+ (BOOL) validateEmail:(NSString *)email
{
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:email];
}
//手机号码验证
+ (BOOL) validateMobile:(NSString *)mobile
{
//手机号以13, 15,18开头,八个 \d 数字字符
NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
return [phoneTest evaluateWithObject:mobile];
}
#pragma mark -密码是否为密码长度由6-16位之间的数字与字母组成
- (BOOL)isValidateNumberOrLetter:(NSString*)str min:(int) min max:(int) max
{
if(min<0||max<0||min==max) {
returnfalse;
}
if(min>max) {
inttemp =min;
min=max;
max=temp;
}
NSString*strCheck =[NSStringstringWithFormat:@"^[A-Z0-9a-z_]{%d,%d}",min,max];
NSPredicate*strTest = [NSPredicatepredicateWithFormat:@"SELF MATCHES%@",strCheck];
return[strTestevaluateWithObject:str];
}
http://my.oschina.net/u/1245365/blog/376517