- (BOOL)nameIScorrect:(NSString*)name
{
if (name.length > 16 || name.length < 2) {//长度2-16
return NO;
}
for (int j = 0; j < name.length; j ++) {
UniChar chr = [name characterAtIndex:j];
if(chr < 0x4e00 || chr > 0x9fa5)//unicode中文编码范围是0x4e00~0x9fa5 也有用u4e00~u9fff
{
// if (chr != 0x2022) {//不为分格符 • 不同键盘值不一样
// return NO;
// }
if (![[name substringWithRange:NSMakeRange(j, 1)] isEqualToString:@"•"] && ![[name substringWithRange:NSMakeRange(j, 1)] isEqualToString:@"·"]) {
return NO;
}
}
}
returnYES;
}
- (BOOL)identityIScorrect:(NSString*)birthday
{
int sum = 0;
int weith[17] = {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
for (int i = 0; i < birthday.length - 1; i++) {
NSString *itemString = [birthday substringWithRange:NSMakeRange(i,1)];
sum += weith[i]*[itemString integerValue];
}
int num = sum%11;
char checkCard[11] = {'1', '0','X', '9', '8', '7', '6', '5', '4', '3', '2'};
char lastChar = [birthday characterAtIndex:birthday.length - 1];
if (num == 2 && lastChar == 'x') {
return YES;
}
if (checkCard[num] == lastChar) {
return YES;
}
returnNO;
}
#pragma mark 验证邮箱
- (BOOL)isValidateEmail:(NSString *)email {
NSString *strRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{1,5}";
NSPredicate *predicate = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@", strRegex];
return [predicate evaluateWithObject:email];
}