Created
September 4, 2016 12:25
-
-
Save shileseal/aea55301cf3b0c418ebf8317640438b8 to your computer and use it in GitHub Desktop.
iOS - Utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma mark - 验证输入信息 | |
// 验证email | |
+ (BOOL)isEmail:(NSString *)input { | |
NSString *emailRegex = @"^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\\.][A-Za-z]{2,3}([\\.][A-Za-z]{2})?$"; | |
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; | |
return [emailTest evaluateWithObject:input]; | |
} | |
// 验证手机号 | |
+ (BOOL)isMobileNum:(NSString *)input { | |
NSString * MOBILE = @"^((13[0-9])|(15[^4,\\D])|(18[0,3,5-9]))\\d{8}$"; | |
NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$"; | |
NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$"; | |
NSString * CT = @"^1((33|53|8[09])[0-9]|349)\\d{7}$"; | |
NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE]; | |
NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM]; | |
NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU]; | |
NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT]; | |
BOOL res1 = [regextestmobile evaluateWithObject:input]; | |
BOOL res2 = [regextestcm evaluateWithObject:input]; | |
BOOL res3 = [regextestcu evaluateWithObject:input]; | |
BOOL res4 = [regextestct evaluateWithObject:input]; | |
if (res1 || res2 || res3 || res4 ) { | |
return YES; | |
} else { | |
return NO; | |
} | |
} | |
// 验证身份证号 | |
+ (BOOL)isIdentityCardNo:(NSString *)input { | |
NSString *emailRegex = @"\\d{15}|(\\d{17}([0-9]|X|x)$)"; | |
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; | |
return [emailTest evaluateWithObject:input]; | |
} | |
// 验证邮编 | |
+ (BOOL)isZipCode:(NSString *)input { | |
NSString *emailRegex = @"[1-9]\\d{5}(?!\\d)"; | |
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; | |
return [emailTest evaluateWithObject:input]; | |
} | |
// 验证数字 | |
+(BOOL)isNumber:(NSString *)input { | |
NSString *emailRegex = @"^\\-?([1-9]\\d*|0)(\\.\\d{0,2})?$"; | |
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; | |
return [emailTest evaluateWithObject:input]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment