ios使用常用正则表达式验证密码身份证手机号

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma 正则匹配手机号
+ (BOOL)checkTelNumber:(NSString *) telNumber
{
    NSString *pattern = @^1+[3578]+\d{9};
    NSPredicate *pred = [NSPredicate predicateWithFormat:@SELF MATCHES %@, pattern];
    BOOL isMatch = [pred evaluateWithObject:telNumber];
    return isMatch;
}
  
  
#pragma 正则匹配用户密码6-18位数字和字母组合
+ (BOOL)checkPassword:(NSString *) password
{
    NSString *pattern = @^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9]{6,18};
    NSPredicate *pred = [NSPredicate predicateWithFormat:@SELF MATCHES %@, pattern];
    BOOL isMatch = [pred evaluateWithObject:password];
    return isMatch;
      
}
  
#pragma 正则匹配用户姓名,20位的中文或英文
+ (BOOL)checkUserName : (NSString *) userName
{
    NSString *pattern = @^[a-zA-Z一-龥]{1,20};
    NSPredicate *pred = [NSPredicate predicateWithFormat:@SELF MATCHES %@, pattern];
    BOOL isMatch = [pred evaluateWithObject:userName];
    return isMatch;
      
}
  
  
#pragma 正则匹配用户身份证号15或18位
+ (BOOL)checkUserIdCard: (NSString *) idCard
{
    NSString *pattern = @(^[0-9]{15}$)|([0-9]{17}([0-9]|X)$);
    NSPredicate *pred = [NSPredicate predicateWithFormat:@SELF MATCHES %@, pattern];
    BOOL isMatch = [pred evaluateWithObject:idCard];
    return isMatch;
}
  
#pragma 正则匹员工号,12位的数字
+ (BOOL)checkEmployeeNumber : (NSString *) number
{
    NSString *pattern = @^[0-9]{12};
      
    NSPredicate *pred = [NSPredicate predicateWithFormat:@SELF MATCHES %@, pattern];
    BOOL isMatch = [pred evaluateWithObject:number];
    return isMatch;
      
}
  
#pragma 正则匹配URL
+ (BOOL)checkURL : (NSString *) url
{
    NSString *pattern = @^[0-9A-Za-z]{1,50};
    NSPredicate *pred = [NSPredicate predicateWithFormat:@SELF MATCHES %@, pattern];
    BOOL isMatch = [pred evaluateWithObject:url];
    return isMatch;
      
}

 

posted @   百川hl  阅读(3610)  评论(0编辑  收藏  举报
编辑推荐:
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
阅读排行:
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· DeepSeek火爆全网,官网宕机?本地部署一个随便玩「LLM探索」
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 上周热点回顾(1.20-1.26)
· 【译】.NET 升级助手现在支持升级到集中式包管理
点击右上角即可分享
微信分享提示