iOS 判断邮箱,手机号是否正确

来源:互联网 发布:erp系统网络架构图 编辑:程序博客网 时间:2024/05/16 10:28

//用户注册 验证邮箱格式是否正确

-(BOOL)CheckInput:(NSString *)_text{

    NSString *Regex=@"[A-Z0-9a-z._%+-]+@[A-Z0-9a-z._]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest=[NSPredicate predicateWithFormat:@"SELF MATCHES %@",Regex];
    return [emailTest evaluateWithObject:_text];
    
}
- (IBAction)getbackPasswd:(id)sender {
    if(![self CheckInput:signemailTextField.text]){
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:@"您的邮箱格式不正确,请检查" delegate:self cancelButtonTitle:@"返回" otherButtonTitles:nil, nil];
        [alert show];
    }

}


/*邮箱验证 MODIFIED BY HELENSONG*/
-(BOOL)isValidateEmail:(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];
}


/*手机号码验证 MODIFIED BY HELENSONG*/
-(BOOL) isValidateMobile:(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];
//    NSLog(@"phoneTest is %@",phoneTest);
    return [phoneTest evaluateWithObject:mobile];
}


/*车牌号验证 MODIFIED BY HELENSONG*/ 
BOOL validateCarNo(NSString* carNo) 

    NSString *carRegex = @"^[A-Za-z]{1}[A-Za-z_0-9]{5}$"; 
    NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex]; 
    NSLog(@"carTest is %@",carTest); 
    return [carTest evaluateWithObject:carNo]; 
}


0 0
原创粉丝点击