码迷,mamicode.com
首页 > 移动开发 > 详细

iOS开发常用输入校验

时间:2015-08-28 15:22:55      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:

1、数字字符校验 #define NUMBERSPERIOD @"0123456789." - (BOOL)CheckInput:(NSString *)string { NSCharacterSet *cs; cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERSPERIOD] invertedSet]; NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; BOOL basicTest = [string isEqualToString:filtered]; return basicTest; } 2、判断用户名,在2-16位 - (BOOL)CheckInput:(NSString *)text { NSString*Regex = @"^\\w{2,16}{1}"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELFMATCHES %@", Regex]; return [emailTest evaluateWithObject:text]; } 3、判断手机号码,1开头的十一位数字 - (BOOL)CheckInput:(NSString *)text { NSString *Regex = @"1\\d{10}"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELFMATCHES %@", Regex]; return [emailTest evaluateWithObject:text]; } 4、判断邮箱 - (BOOL)CheckInput:(NSString *)text { NSString *Regex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELFMATCHES %@", Regex]; return [emailTest evaluateWithObject:text]; } 5、判断密码,6-16位 - (BOOL)CheckInput:(NSString *)text { NSString *Regex = @"\\w{6,16}"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELFMATCHES %@", Regex]; return [emailTest evaluateWithObject:text]; }

iOS开发常用输入校验

标签:

原文地址:http://www.cnblogs.com/QQ765286788/p/4766356.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!