#pragma mark - 检测非法字符lua
/*手机号码验证 MODIFIED BY HELENSONGspa
* 正确返回trueorm
*/it
-(BOOL) isValidateMobile:(NSString *)mobiletable
{ast
//手机号以13, 15,18开头,八个 \d 数字字符验证码
NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";class
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];登录
// NSLog(@"phoneTest is %@",phoneTest);cli
return [phoneTest evaluateWithObject:mobile];
}
登陆点击按钮
- (void)button{
if (![self isValidateMobile:userName.text])
{
[MTHint toast:@"请输入正确手机号" toView:weakSelf.view displaytime:3];
return;
}
}
//姓名只能由中文、字母或数字组成
- (BOOL)isValidateUser:(NSString *)text
{
NSString * regex = @"^[a-zA-Z0-9_\u4e00-\u9fa5]+$";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
return [pred evaluateWithObject:text];
}
//验证码,由0到9,6位数
- (BOOL)isValidateNumber:(NSString *)text
{
NSString * regex = @"^[0-9]{6}";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
return [pred evaluateWithObject:text];
}
在UIAlert方法里
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
XLOG(@"%d",buttonIndex);
if (buttonIndex == 1)
{
//获得输入框
UITextField *tf=[alertView textFieldAtIndex:0];
if ([tf.text trimWhitespace].length <= 0)
{
[MTHint toast:@"不能为空" toView:self.view displaytime:2.0f];
return;
}
if (![self isValidateUser:tf.text])
{
[MTHint toast:@"姓名只能由中文、字母或数字组成" toView:self.view displaytime:2.0f];
return;
}
if (tf.text.length >= 10)
{
[MTHint toast:@"姓名需少于10个字符" toView:self.view displaytime:2];
return;
}
[titleValues replaceObjectAtIndex:1 withObject:tf.text];
nameValue = tf.text;
XLOG(@"%@",tf.text);
[_tableView reloadData];
}
}