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

}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。