Objective C email 형식 확인하기
https://play.google.com/store/apps/details?id=com.danchoo.tagalbum&hl=ko
- (BOOL)checkValidEmail:(NSString*)email stricterFilter:(BOOL)stricterFilter {
BOOL result = NO;
if (email == nil) {
return result;
}
NSString *stricterFilterString = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSString *laxString = @".+@.+\\.[A-Za-z]{2}[A-Za-z]*";
NSString *emailRegex = stricterFilter ? stricterFilterString : laxString;
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
result = [emailTest evaluateWithObject:email];
return result;
}
https://smartstore.naver.com/happysiso
stricterFilter 는 좀더 엄격한 기준을가지고 메일 형식을 확인하는 flag다.
필요에따라 아래와 같이 stricterFilter flag를 삭제하고 해도 무방하다.
- (BOOL)checkValidEmail:(NSString*)email {
BOOL result = NO;
if (email == nil) {
return result;
}
NSString *stricterFilterString = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", stricterFilterString];
result = [emailTest evaluateWithObject:email];
return result;
}
댓글