其他驗(yàn)證可查看URL:判斷01??判斷02??判斷03??判斷04
一加派、驗(yàn)證移動(dòng)手機(jī)號(hào):
+ (BOOL)isMobile:(NSString*)mobile{
??NSString *regex = @"^1+[34578]+\d{9}";
??NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
??return[pred evaluateWithObject:mobile];
}
二、郵箱驗(yàn)證:
+ (BOOL)isEmail:(NSString*)email{
??NSString *regex = @"^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$";
??NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
??return[pred evaluateWithObject:email];
}
三垛耳、整形驗(yàn)證
+ (BOOL)isPureInt:(NSString*)string{
??NSScanner* scan = [NSScanner scannerWithString:string];
??intval;
??return[scan scanInt:&val] && [scan isAtEnd];
}
四、浮點(diǎn)型驗(yàn)證
- (BOOL)isPureFloat:(NSString*)string{
??NSScanner* scan = [NSScanner scannerWithString:string];
??floatval;
??return[scan scanFloat:&val] && [scan isAtEnd];
}
五慎式、中文驗(yàn)證
+ (BOOL)isURL:(NSString*)url{
??NSString *regex = @"[a-zA-z]+://[^\s]*";
??NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
??return[pred evaluateWithObject: url];
}
六型宙、網(wǎng)址URL驗(yàn)證
+ (BOOL)isURL:(NSString*)url{
??NSString *regex = @"[a-zA-z]+://[^\s]*";
??NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
??return[pred evaluateWithObject: url];
}
七疮茄、身份證號(hào)驗(yàn)證(比較繁瑣)
+ (BOOL)verifyIDCardNumber:(NSString *)IDCardNumber?{
IDCardNumber = [IDCardNumber stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if([IDCardNumber length] != 18){
returnNO;
}
NSString *mmdd = @”(((0[13578]|1[02])(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)(0[1-9]|[12][0-9]|30))|(02(0[1-9]|[1][0-9]|2[0-8])))”;
NSString *leapMmdd = @”0229”;
NSString *year = @”(19|20)[0-9]{2}”;
NSString *leapYear = @”(19|20)(0[48]|[2468][048]|[13579][26])”;
NSString *yearMmdd = [NSString stringWithFormat:@”%@%@”, year, mmdd];
NSString *leapyearMmdd = [NSString stringWithFormat:@”%@%@”, leapYear, leapMmdd];
NSString *yyyyMmdd = [NSString stringWithFormat:@”((%@)|(%@)|(%@))”, yearMmdd, leapyearMmdd, @”20000229”];
NSString *area = @”(1[1-5]|2[1-3]|3[1-7]|4[1-6]|5[0-4]|6[1-5]|82|[7-9]1)[0-9]{4}”;
NSString *regex = [NSString stringWithFormat:@”%@%@%@”, area, yyyyMmdd , @”[0-9]{3}[0-9Xx]”];
NSPredicate *regexTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
if(![regexTest evaluateWithObject:IDCardNumber]){
??returnNO;
}
intsummary = ([IDCardNumber substringWithRange:NSMakeRange(0,1)].intValue + [IDCardNumber substringWithRange:NSMakeRange(10,1)].intValue) *7
+ ([IDCardNumber substringWithRange:NSMakeRange(1,1)].intValue + [IDCardNumber substringWithRange:NSMakeRange(11,1)].intValue) *9
+ ([IDCardNumber substringWithRange:NSMakeRange(2,1)].intValue + [IDCardNumber substringWithRange:NSMakeRange(12,1)].intValue) *10
+ ([IDCardNumber substringWithRange:NSMakeRange(3,1)].intValue + [IDCardNumber substringWithRange:NSMakeRange(13,1)].intValue) *5
+ ([IDCardNumber substringWithRange:NSMakeRange(4,1)].intValue + [IDCardNumber substringWithRange:NSMakeRange(14,1)].intValue) *8
+ ([IDCardNumber substringWithRange:NSMakeRange(5,1)].intValue + [IDCardNumber substringWithRange:NSMakeRange(15,1)].intValue) *4
+ ([IDCardNumber substringWithRange:NSMakeRange(6,1)].intValue + [IDCardNumber substringWithRange:NSMakeRange(16,1)].intValue) *2
+ [IDCardNumber substringWithRange:NSMakeRange(7,1)].intValue *1+ [IDCardNumber substringWithRange:NSMakeRange(8,1)].intValue *6
+ [IDCardNumber substringWithRange:NSMakeRange(9,1)].intValue *3;
NSInteger remainder = summary % 11;
NSString *checkBit = @"";
NSString *checkString = @"10X98765432";
checkBit = [checkString substringWithRange:NSMakeRange(remainder,1)];// 判斷校驗(yàn)位
return[checkBit isEqualToString:[[IDCardNumber substringWithRange:NSMakeRange(17,1)] uppercaseString]];}
八、一般用戶名的驗(yàn)證
+ (BOOL) isUserName:(NSString *)name{
??NSString *userNameRegex = @"^[A-Za-z0-9]{6,20}+$";
??NSPredicate *userNamePredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",userNameRegex]员咽;?
??return[userNamePredicate evaluateWithObject:name];
}
九·判斷手機(jī)號(hào)碼毒涧、固話
{
??if(mobileNum.length != 11) {
????returnNO;
??}
??/**
???* 手機(jī)號(hào)碼:
???* 13[0-9], 14[5,7], 15[0, 1, 2, 3, 5, 6, 7, 8, 9], 17[6, 7, 8], 18[0-9], 170[0-9]
???* 移動(dòng)號(hào)段: 134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,178,1705
???* 聯(lián)通號(hào)段: 130,131,132,155,156,185,186,145,176,1709
???* 電信號(hào)段: 133,153,180,181,189,177,1700
???*/
??NSString *MOBILE = @"^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[0678])\\d{8}$";
??/**
???* 中國移動(dòng):China Mobile
???* 134,135,136,137,138,139,150,151,152,157,158,159,182,183,184,187,188,147,178,1705
???*/
??NSString *CM = @"(^1(3[4-9]|4[7]|5[0-27-9]|7[8]|8[2-478])\\d{8}$)|(^1705\\d{7}$)";
??/**
???* 中國聯(lián)通:China Unicom
???* 130,131,132,155,156,185,186,145,176,1709
???*/
??NSString *CU = @"(^1(3[0-2]|4[5]|5[56]|7[6]|8[56])\\d{8}$)|(^1709\\d{7}$)";
??/**
???* 中國電信:China Telecom
???* 133,153,180,181,189,177,1700
???*/
??NSString *CT = @"(^1(33|53|77|8[019])\\d{8}$)|(^1700\\d{7}$)";
??/**
???25???? * 大陸地區(qū)固話及小靈通
???26???? * 區(qū)號(hào):010,020,021,022,023,024,025,027,028,029
???27???? * 號(hào)碼:七位或八位
???28???? */
??//? NSString * PHS = @"^(0[0-9]{2})\\d{8}$|^(0[0-9]{3}(\\d{7,8}))$";
??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];
??if(([regextestmobile evaluateWithObject:mobileNum] == YES)
????|| ([regextestcm evaluateWithObject:mobileNum] == YES)
????|| ([regextestct evaluateWithObject:mobileNum] == YES)
????|| ([regextestcu evaluateWithObject:mobileNum] == YES)) ?{
????returnYES;
??} ?else{
????returnNO; ?}}