일상+

이메일 및 휴대전화 형식 체크 본문

iPhone

이메일 및 휴대전화 형식 체크

이종준 2015. 7. 31. 16:27

* 이메일 형식


- (NSTextCheckingResult )emailValidCheck:(NSString )emailId
{
    NSString expression = @"^[A-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z]{2,4}$";
    NSError error = NULL;
     
    NSRegularExpression regex = [NSRegularExpression regularExpressionWithPattern:expression options:NSRegularExpressionCaseInsensitive error:&error];
     
    NSTextCheckingResult match = [regex firstMatchInString:emailId options:0 range:NSMakeRange(0, [emailId length])];
     
    return match;
}



* 휴대전화 형식


- (NSTextCheckingResult )phoneNumberValidCheck:(NSString )emailId

{

    NSString expression = @"^(01[016789]{1}|02|0[3-9]{1}[0-9]{1})?[0-9]{3,4}?[0-9]{4}$";

    NSError error = NULL;

     

    NSRegularExpression regex = [NSRegularExpression regularExpressionWithPattern:expression                                                options:NSRegularExpressionCaseInsensitive error:&error];

     

    NSTextCheckingResult match = [regex firstMatchInString:emailId options:0 range:NSMakeRange(0, [emailId length])];

     

    return match;

}



Comments