美文网首页
IOS正则表达式---by talent.L

IOS正则表达式---by talent.L

作者: 天才iOS程序员 | 来源:发表于2017-02-19 19:36 被阅读33次

    常用正则表示

    1.QQ号

    //数字组成 10000开始

    NSString * str =@"[1-9][0-9]{4,}";

    2.网址

    NSString * str =@"((http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)|(www.[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)";

    3身份证

    NSString *str = @"/(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)/";

    4手机号

    NSString *str1 = @"^((13[0-9])|(15[^4,\\D])|(18[0-9])|(14[57])|(17[013678]))\\d{8}$";

    5电子邮箱

    NSString *str1 = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";

    if (self.yhjtext.text.length >0) {

    //16或19位银行卡号

    NSString * str =@"^([0-9]{16}|[0-9]{19})$";

    //谓词

    NSPredicate * pre =[NSPredicate predicateWithFormat:@"self matches %@",str];

    BOOL is =[pre evaluateWithObject: self.yhjtext.text];

    if (is) {

    UIAlertController * alert =[UIAlertController alertControllerWithTitle:@"银行卡号标明" message:@"正确" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction * ac1 =[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    }];

    UIAlertAction * ac2 =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

    }];

    [alert addAction:ac1];

    [alert addAction:ac2];

    [self presentViewController:alert animated:NO completion:^{

    }];

    }

    else{

    UIAlertController * alert =[UIAlertController alertControllerWithTitle:@"银行卡号码标明" message:@"不正确" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction * ac1 =[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    }];

    UIAlertAction * ac2 =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

    }];

    [alert addAction:ac1];

    [alert addAction:ac2];

    [self presentViewController:alert animated:NO completion:^{

    }];

    }

    }

    相关文章

      网友评论

          本文标题:IOS正则表达式---by talent.L

          本文链接:https://www.haomeiwen.com/subject/eabjwttx.html