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

    }

  • 相关阅读:
    507.Perfect Number
    441.Arranging Coins
    344.Reverse String
    160.Intersection of Two Linked Lists
    HDU-2521 反素数
    HDU-2710 Max Factor
    HDU-2552 三足鼎立
    HDU-2549 壮志难酬
    HDU-2548 两军交锋
    HDU-2550 百步穿杨
  • 原文地址:https://www.cnblogs.com/sun-wsh/p/5732885.html
Copyright © 2011-2022 走看看