手機(jī)號(hào)
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}$";
- 電話號(hào)碼以 13 , 15 , 18 開(kāi)頭
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];
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者