美文网首页
XcodePoints(正则表达式)

XcodePoints(正则表达式)

作者: weiwei_js | 来源:发表于2019-06-03 17:44 被阅读0次

一,正则表达式:

^(0|[1-9]\d{0,6})([.]?\d{1,2})?$

^,$ :开始和结尾;

|:或者;

[1-9] : 允许输入1到9 的数据;

{0,6} :允许输入0到6位;

[.]?  : 如果有小数点;

{1,2} :小数部分,1到2位;

二,正则表达式判断是不是手机号:

    /**

     *手机号码

     *移动:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188

     *联通:130,131,132,152,155,156,185,186

     *电信:133,1349,153,180,189,181(增加)

     */

- (BOOL) isMobile:(NSString *)mobileNumbel{

    NSString * MOBIL = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";

//中国移动:China Mobile

    NSString * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[2378])\\d)\\d{7}$";

//中国联通:China Unicom

    NSString * CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";

//中国电信:China Telecom

    NSString * CT = @"^1((33|53|8[019])[0-9]|349)\\d{7}$";

    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBIL];

    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];

    NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];

    NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];

    BOOL isMobile = NO;

    if (([regextestmobile evaluateWithObject:mobileNumbel]

         || [regextestcm evaluateWithObject:mobileNumbel]

         || [regextestct evaluateWithObject:mobileNumbel]

         || [regextestcu evaluateWithObject:mobileNumbel])) {

        isMobile = YES;

    }

    return isMobile;

}

褚小者不可以怀大,绠短者不可以汲深。

相关文章

  • XcodePoints(正则表达式)

    一,正则表达式: ^(0|[1-9]\d{0,6})([.]?\d{1,2})?$ ^,$ :开始和结尾; |:或...

  • XcodePoints(一)

    1,App Store 相关: App Store 软件更新(如Xcode),最好不要直接下载,直接在更新里点击更...

  • XcodePoints(二)

    1,Xcode 10 代码块管理: 添加新的代码块:选中代码》右键》选择 Create Code Snippet;...

  • XcodePoints(字符串)

    一,字符串之间比较: [strAisEqualToString:strB] ; //字符串之间比较: [A is...

  • Linux命令行与Shell脚本编程大全-shell正则表达式

    本章内容: 定义正则表达式 了解基本正则表达式 扩展正则表达式 创建正则表达式 定义正则表达式 正则表达式是你定义...

  • 正则相关

    正则表达式基本语法 正则表达式常见字符 正则表达式特殊字符 正则表达式数量词 正则表达式边界匹配 正则表达式逻辑或...

  • 正则表达式系列-1

    正则表达式系列-1正则表达式系列-2正则表达式系列-3正则表达式系列-4 什么是正则表达式 正则表达式就是用事先定...

  • 正则表达式

    正则表达式 - 教程正则表达式 - 简介正则表达式 - 语法正则表达式 - 元字符正则表达式 - 运算符优先级正则...

  • Python基础入门 - 正则表达式与综合实战

    1. 初识正则表达式 1.1 介绍 步骤介绍正则表达式入门及应用正则表达式的进阶正则表达式案例 1.2 正则表达式...

  • Java正则表达式参考

    Java正则表达式入门 java正则表达式应用 深入浅出之正则表达式(一) 深入浅出之正则表达式(二) 正则表达式...

网友评论

      本文标题:XcodePoints(正则表达式)

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