标签:ar sp for on log bs ad as tt
#pragma mark - 检测非法字符
//姓名只能由中文、字母或数字组成
- (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];
}
}
标签:ar sp for on log bs ad as tt
原文地址:http://www.cnblogs.com/rankilau/p/4146714.html