#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];
}
}