NSString *regexString = @”00[0-9]{3}$”;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexString options:NSRegularExpressionAnchorsMatchLines error:nil];
NSArray *matches = [regex matchesInString:self.textField.text options:NSMatchingAnchored range:NSMakeRange(0, [self.textField.text length])];
if ([matches count]) {
// 如果数组不为空
} else {
// 创建警告控制器
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请检查股票代码格式" message:nil preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}]];
[self presentViewController:alert animated:YES completion:^{
}];
}
通过正则表达式判断TextField内容是否符合要求
最新推荐文章于 2023-02-09 10:18:22 发布