//是否是纯数字
+ (BOOL)isNumText:(NSString *)str{
NSString * regex = @"(/^[0-9]*$/)";
NSPredicate * pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
BOOL isMatch = [pred evaluateWithObject:str];
if (isMatch) {
return YES;
}else{
return NO;
}
}
- (NSString *) trimming {
return [self stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];
}
//判断是不是纯数字
[NSCharacterSet decimalDigitCharacterSet];
if ([[textField.text stringByTrimmingCharactersInSet: [NSCharacterSet decimalDigitCharacterSet]]trimming].length >0) {
DLog(@"不是纯数字");
}else{
DLog(@"纯数字!");
}
//正则表达式匹配11位手机号码
NSString *regex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
BOOL isMatch = [pred evaluateWithObject:_telField.text];
if(isMatch) { //有效手机号
}else//无效手机号
{
if (ios7) {
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:@"无效的手机号码,请重新输入..." delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil nil];
alertView.tag = 104;
[alertView show];
}else
{
UIAlertController*alertController = [UIAlertController alertControllerWithTitle:nil message:@"无效的手机号码,请重新输入..." preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction*action) {
[_telField selectAll:self];
}];
[alertController addAction:otherAction];
[self presentViewController:alertController animated:YES completion:nil];
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有