亻五毛

导航

ios-邮箱正则表达式判断

- (void)loadData {

     NSMutableArray *array = [NSMutableArray arrayWithCapacity:10];

    if ([self.title isEqualToString:@"名字"]) {

        self.nameStr = inputTextField.text;

    [array addObject:[NSDictionary dictionaryWithObject:self.nameStr forKey:@"memberNm"]];

    }else if ([self.title isEqualToString:@"邮箱"]){

        self.emailStr = inputTextField.text;

       BOOL emailOK= [self validateEmail:self.emailStr];

        if (!emailOK) {

            [UIAlertView showMessage:@"邮箱格式不正确" title:@"警告"];

            return;

        }

    [array addObject:[NSDictionary dictionaryWithObject:self.emailStr forKey:@"memberEmail"]];

    }else if([self.title isEqualToString:@"其它联系方式"]){

        self.otherStr = inputTextField.text;

      

    [array addObject:[NSDictionary dictionaryWithObject:self.otherStr forKey:@"memberContacts"]];

    }else if ([self.title isEqualToString:@"岗位分工"]){

        self.jobdivison = inputTextField.text;

        [array addObject:[NSDictionary dictionaryWithObject:self.jobdivison forKey:@"memberDesc"]];

    }

    self.request = [UPRequest postDataWithPathName:@"member/updateMember" delegate:self params:array];

}

 

 

//邮箱正则表达式判断

-(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];

}

posted on 2014-09-04 15:08  五尐毛  阅读(285)  评论(0编辑  收藏  举报