
下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
///// 手机号码的有效性判断//检测是否是手机号码- (BOol)isMobileNumber:(Nsstring *)mobileNum{ /** * 手机号码 * 移动: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 */ Nsstring * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\d{8}$"; /** 10 * 中国移动:China Mobile 11 * 134[0-8],188 12 */ Nsstring * CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\d)\d{7}$"; /** 15 * 中国联通:China Unicom 16 * 130,186 17 */ Nsstring * CU = @"^1(3[0-2]|5[256]|8[56])\d{8}$"; /** 20 * 中国电信:China Telecom 21 * 133,189 22 */ Nsstring * CT = @"^1((33|53|8[09])[0-9]|349)\d{7}$"; /** 25 * 大陆地区固话及小灵通 26 * 区号:010,020,021,022,023,024,025,027,028,029 27 * 号码:七位或八位 28 */ // Nsstring * PHS = @"^0(10|2[0-5789]|\d{3})\d{7,8}$"; nspredicate *regextestmobile = [nspredicate predicateWithFormat:@"SELF MATCHES %@",MOBILE]; nspredicate *regextestcm = [nspredicate predicateWithFormat:@"SELF MATCHES %@",CM]; nspredicate *regextestcu = [nspredicate predicateWithFormat:@"SELF MATCHES %@",CU]; nspredicate *regextestct = [nspredicate predicateWithFormat:@"SELF MATCHES %@",CT]; if (([regextestmobile evaluateWithObject:mobileNum] == YES) || ([regextestcm evaluateWithObject:mobileNum] == YES) || ([regextestct evaluateWithObject:mobileNum] == YES) || ([regextestcu evaluateWithObject:mobileNum] == YES)) { return YES; } else { return NO; }}//////// 特殊字符的限制输入,价格金额的有效性判断#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条)