IOS 휴대폰 번호, 전화번호, 메일박스, 주소, 우편번호 검증

1610 단어

메일박스

// 

+ (BOOL) validateEmail:(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) validateMobile:(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];

return [phoneTest evaluateWithObject:mobile];

}

좌석 번호 검증

// 

+ (BOOL) validateTelphone:(NSString *)telphone

{

NSString *phoneRegex = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";

NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];

return [phoneTest evaluateWithObject:telphone];

}

URL 인증

//URL 

+ (BOOL) validateUrl:(NSString *)url

{

NSString *regex = @"http(s)?:\\/\\/([\\w-]+\\.)+[\\w-]+(\\/[\\w- .\\/?%&=]*)?";

NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];

return [pred evaluateWithObject:url];

}

우편번호 검증

// 

+ (BOOL) validateZipCode:(NSString *)zipCode

{

NSString *regex = @"[0-9]\\d{5}(?!\\d)";

NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];

return [pred evaluateWithObject:zipCode];

}

좋은 웹페이지 즐겨찾기