//正則表達式,判斷手機號碼格式是否正確
- (BOOL)checkTel:(NSString *)str
{
NSString *regex = @"^((13[0-9])|(147)|(15[^4,\\D])|(18[0,5-9]))\\d{8}$";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
BOOL isMatch = [pred evaluateWithObject:str];
if (!isMatch) {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"請輸入正確的手機號碼" delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
[alert show];
return NO;
}
return YES;
}
//正則判斷郵箱格式是否正確
- (BOOL)validateEmail:(NSString *)email
{
NSLog(@"3333333");
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
BOOL isMatch = [emailTest evaluateWithObject:email];
if (!isMatch) {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"請輸入正確的郵箱" delegate:nil cancelButtonTitle:@"確定" otherButtonTitles:nil, nil];
[alert show];
return NO;
}
return YES;
}