惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
F
Fortinet All Blogs
Cloudbric
Cloudbric
P
Palo Alto Networks Blog
T
Threatpost
T
Tor Project blog
T
Tenable Blog
AWS News Blog
AWS News Blog
Project Zero
Project Zero
L
LangChain Blog
Cyberwarzone
Cyberwarzone
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Security Latest
Security Latest
云风的 BLOG
云风的 BLOG
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
MongoDB | Blog
MongoDB | Blog
aimingoo的专栏
aimingoo的专栏
K
Kaspersky official blog
Jina AI
Jina AI
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
TaoSecurity Blog
TaoSecurity Blog
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
IT之家
IT之家
Forbes - Security
Forbes - Security
The Hacker News
The Hacker News
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Y
Y Combinator Blog

博客园 - Longkin

ios9+xcode7 适配笔记 xsd、wsdl生成C#类的命令行工具使用方法 xcode更新,想想也是醉了 关于#define预处理指令的一个问题 UITextField实现左侧空出一定的边距 IOS判断app在appstore是否有可用的更新 我的第二个app上线:术购管家 百度地图 IOS版开发经验分享 最新app store 应用提交经验分享 用C#做的软件界面 由windows server2012 想起 关于团队合作的一点认识 由“美图秀秀”软件的网站,看网站的生存模式 下个月计划【2009-5】 对新网好失望,郁闷中 如何实现asp.net页面的美观性? 关于UpdatePanel和页面刷新的问题 新手看SEO网站优化 转载---Web 2.0 新名词:Widget
IOS动态判断UITextField是否输入为手机号
Longkin · 2014-12-12 · via 博客园 - Longkin

现在使用的app大部分都用到手机号注册,很多app注册的时候会判断手机号,可以根据当前输入文本来判断“获取验证码”的按钮是否可用

判断输入文本是通过UITextField的代理的

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

方法实现的。

可以的判断输入和删除字符时是否为手机号

实现代码如下

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (textField.tag == 1001) {
        NSInteger strLength = textField.text.length - range.length + string.length;
        if (strLength > 11){
            return NO;
        }
        NSString *text = nil;
        //如果string为空,表示删除
        if (string.length > 0) {
            text = [NSString stringWithFormat:@"%@%@",textField.text,string];
        }else{
            text = [textField.text substringToIndex:range.location];
        }
        if ([self isMobile:text]) {
            [btnVeriy setEnabled:YES];
        }else{
            [btnVeriy setEnabled:NO];
        }
    }
    return YES;
}