手机号
NSString *CM_NUM = @"^((13[4-9])|(147)|(15[0-2,7-9])|(178)|(18[2-4,7-8]))\\d{8}|(1705)\\d{7}$";
NSString *CU_NUM = @"^((13[0-2])|(145)|(15[5-6])|(176)|(18[5,6]))\\d{8}|(1709)\\d{7}$";
NSString *CT_NUM = @"^((133)|(153)|(177)|(18[0,1,9]))\\d{8}$";
NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
判断是不是 Email
+ (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];
}
判断是不是money
+ (BOOL)validaeMoney:(NSString *)money {
NSString *phoneRegex = @"^[0-9]+(\\.[0-9]{1,2})?$";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
return [phoneTest evaluateWithObject:money];
}
昵称 ,用户名 ,密码 判断
+ (BOOL)validateUsername:(NSString *)username {
NSString *userNameRegex = @"^[A-Za-z0-9\u4e00-\u9fa5]{4,20}+$";
NSPredicate *userNamePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",userNameRegex];
return [userNamePredicate evaluateWithObject:username];
}
+ (BOOL)validateNickname:(NSString *)nickname {
NSString *nicknameRegex = @"^[A-Za-z0-9\u4e00-\u9fa5_-]{1,20}+$";
NSPredicate *nicknamePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", nicknameRegex];
return [nicknamePredicate evaluateWithObject:nickname];
}
+ (BOOL)validatePassword:(NSString *)password {
NSString *passwordRegex = @"^[a-zA-Z0-9-]{6,20}+$";
NSPredicate *passwordPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passwordRegex];
return [passwordPredicate evaluateWithObject:password];
}
网友评论