ios는 메일박스, 핸드폰 번호, 자동차 번호가 합법적인지 판단(정칙 표현)

5721 단어
/*  MODIFIED BY HELENSONG*/
-(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];
}

/*  MODIFIED BY HELENSONG*/
-(BOOL) isValidateMobile:(NSString *)mobile
{
    // 13, 15,18 ,  \d  
    NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
//    NSLog(@"phoneTest is %@",phoneTest);
    return [phoneTest evaluateWithObject:mobile];
}

/*  MODIFIED BY HELENSONG*/ 
BOOL validateCarNo(NSString* carNo) 
{ 
    NSString *carRegex = @"^[A-Za-z]{1}[A-Za-z_0-9]{5}$"; 
    NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex]; 
    NSLog(@"carTest is %@",carTest); 
    return [carTest evaluateWithObject:carNo]; 
}

좋은 웹페이지 즐겨찾기