zoukankan      html  css  js  c++  java
  • 正则表达式

    //包含数字和字母的密码长度6-16位

    -(BOOL) validatePassword:(NSString *)password

    {

        //密码正则表达式

        NSString *passwordRegex = @"^(?=.*?[a-zA-Z])(?=.*?[0-9])[a-zA-Z0-9]{6,16}$";

        NSPredicate *passwordTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",passwordRegex];

        return [passwordTest evaluateWithObject:password];

    }

    -(BOOL) validateEmail:(NSString *)email

    {

        //邮箱正则表达式

        NSString *emailRegex = @"^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$";

        NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",emailRegex];

        return [emailTest evaluateWithObject:email];

    }

    //手机号匹配11,12,13,14,15,16,17,18,19开头

    -(BOOL) validateMobile:(NSString *)mobile

    {

        //手机正则表达式

        NSString *mobileRegex = @"^(1[123456789][0-9]{9})$";

        NSPredicate *mobileTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",mobileRegex];

        return [mobileTest evaluateWithObject:mobile];

    }

    -(BOOL) validateTel:(NSString *)tel

    {

        //传真,固定电话正则表达式

        NSString *phoneRegex = @"^(([0\+]\d{2,3}-)?(0\d{2,3})-)?(\d{7,8})(-(\d{3,}))?$";

        NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];

        return [phoneTest evaluateWithObject:tel];

    }

  • 相关阅读:
    XML HTML
    git教程
    GIT过滤
    HTTP
    golang json
    golang type 和断言 interface{}转换
    tcp参数设置
    tcp状态-TIME_WAIT与CLOSE_WAIT带来的坑
    tcp状态
    文件描述符与socket连接
  • 原文地址:https://www.cnblogs.com/sun-wsh/p/5732885.html
Copyright © 2011-2022 走看看