//邮箱地址的正则表达式
- (BOOL)isValidateEmail:(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];
}
// 身份证号码判断
- (BOOL)isCorrect:(NSString *)IDNumber
{
if (IDNumber.length < 18) {
return NO;
}
NSMutableArray *IDArray = [NSMutableArray array];
// 遍历身份证字符串,存入数组中
for (int i = 0; i < 18; i++) {
NSRange range = NSMakeRange(i, 1);
NSString *subString = [IDNumber substringWithRange:range];
[IDArray addObject:subString];
}
// 系数数组
NSArray *coefficientArray = [NSArray arrayWithObjects:@"7", @"9", @"10", @"5", @"8", @"4", @"2", @"1", @"6", @"3",@"7", @"9", @"10", @"5", @"8", @"4", @"2", nil];
// 余数数组
NSArray *remainderArray = [NSArray arrayWithObjects:@"1", @"0", @"X", @"9", @"8", @"7", @"6", @"5", @"4", @"3",@"2", nil];
// 每一位身份证号码和对应系数相乘之后相加所得的和
int sum = 0;
for (int i = 0; i < 17; i++) {
int coefficient = [coefficientArray[i] intValue];
int ID = [IDArray[i] intValue];
sum += coefficient * ID;
}
// 这个和除以11的余数对应的数
NSString *str = remainderArray[(sum % 11)];
// 身份证号码最后一位
NSString *string = [IDNumber substringFromIndex:17];
// 如果这个数字和身份证最后一位相同,则符合国家标准,返回YES
if ([str isEqualToString:string]) {
return YES;
} else {
return NO;
}
}
~~~
网友评论