//该方法可判断输入的是否为数字后两位
- (BOOL) validateNumber:(NSString *)number
{
NSString *numberRegex = @"^((?!0*$)[0-9]+(\\.(?=.*[0-9])[0-9]{2})?|(?!0*$)[0-9]+(\\.(?=.*[0-9])[0-9]{1})?)$";
NSPredicate *numberTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",numberRegex];
return [numberTest evaluateWithObject:number];
}
//该方法可判断输入的是否为数字
- (BOOL) validatePositiveNumber:(NSString *)positiveNumber
{
NSString *positivenumberRegex = @"^[0-9]*$";
NSPredicate *positivenumberTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",positivenumberRegex];
return [positivenumberTest evaluateWithObject:positiveNumber];
}
//该方法可判断你输入的是否为正确的电话号码
- (BOOL) validateMobile:(NSString *)mobile
{
NSString *phoneRegex = @"^((13[0-9])|(15[0-9])|(18[0,0-9])|(177)(|176)|(178)|(147)|(145))\\d{8}$";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
return [phoneTest evaluateWithObject:mobile];
}