下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
一:正则表达式再用#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 正则匹配用户身份z号 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; }二 Textfiled的代理方法//////// 特殊字符的限制输入,价格金额的有效性判断#define myDotNumbers @"0123456789.\n"#define myNumbers @"0123456789\n"-(voID) createTextfiled { textfIEld1_ = [[UITextFIEld alloc] initWithFrame:CGRectMake(0,20,20)]; textfIEld1_.delegate = self; [self addSubvIEw:textfIEld1_]; textfIEld2_ = [[UITextFIEld alloc] initWithFrame:CGRectMake(0,20)]; textfIEld2_.delegate = self; [self addSubvIEw:textfIEld2_]; textfIEld3_ = [[UITextFIEld alloc] initWithFrame:CGRectMake(0,20)]; textfIEld3_.delegate = self; [self addSubvIEw:textfIEld3_];}-(voID)showMyMessage:(Nsstring*)aInfo { UIAlertVIEw *alertVIEw = [[UIAlertVIEw alloc] initWithTitle:@"提示" message:aInfo delegate:self cancelbuttonTitle:@"确定" otherbuttonTitles:nil,nil]; [alertVIEw show]; [alertVIEw release];}- (BOol)textFIEld:(UITextFIEld *)textFIEld shouldChangeCharactersInRange:(NSRange)range replacementString:(Nsstring *)string { NSCharacterSet *cs; if ([textFIEld isEqual:textfIEld1_]) { cs = [[NSCharacterSet characterSetWithCharactersInString:myNumbers] invertedSet]; Nsstring *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; BOol basicTest = [string isEqualToString:filtered]; if (!basicTest) { [self showMyMessage:@"只能输入数字"]; return NO; } } else if ([textFIEld isEqual:textfIEld2_]) { cs = [[NSCharacterSet characterSetWithCharactersInString:myNumbers] invertedSet]; Nsstring *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; BOol basicTest = [string isEqualToString:filtered]; if (!basicTest) { [self showMyMessage:@"只能输入数字"]; return NO; } } else if ([textFIEld isEqual:textfIEld3_]) { NSUInteger nDotLoc = [textFIEld.text rangeOfString:@"."].location; if (NSNotFound == nDotLoc && 0 != range.location) { cs = [[NSCharacterSet characterSetWithCharactersInString:myDotNumbers] invertedSet]; } else { cs = [[NSCharacterSet characterSetWithCharactersInString:myNumbers] invertedSet]; } Nsstring *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""]; BOol basicTest = [string isEqualToString:filtered]; if (!basicTest) { [self showMyMessage:@"只能输入数字和小数点"]; return NO; } if (NSNotFound != nDotLoc && range.location > nDotLoc + 3) { [self showMyMessage:@"小数点后最多三位"]; return NO; } } return YES;}
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的iOS关于判断输入的密码是否合法,价格动态判断合法性全部内容,希望文章能够帮你解决iOS关于判断输入的密码是否合法,价格动态判断合法性所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)