OC -- textfield输入时正则谓词匹配中英文

前端之家收集整理的这篇文章主要介绍了OC -- textfield输入时正则谓词匹配中英文前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

NSString *zhengze=@"^([a-z0-9]+\\.?(?:com|cn|mobi|co|net|so|org|gov|tel|tv|biz|cc|hk|name|info|asia|me)?(?:\\.?(?:cn))?)$";

NSPredicate *pre=[NSPredicatepredicateWithFormat:@"SELF MATCHES %@",zhengze];

if (![pre evaluateWithObject:searchText.text]) {

UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:nilmessage:@"对不起,您输入的域名格式有误\n请重新输入!\n\n例如:abc/abc.com" delegate:self cancelButtonTitle:@"确定"otherButtonTitles:nil,nil];

[alert show];

[alert release];

searchText.text=@"";

}

NSString *match =@"^([a-z0-9]*[\u4e00-\u9fa5]+[a-z0-9]*\\.?(?:com|net|tv|biz|cc|公司|网络|中国)?)$";

NSPredicate *predicate = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",match];

if(![predicate evaluateWithObject:textField.text]){

UIAlertView *alert = [[UIAlertViewalloc] initWithTitle:nilmessage:@"对不起,您输入的域名格式有误\n请重新输入!\n\n例如:万网/万网.com" delegate:self cancelButtonTitle:@"确定"otherButtonTitles:nil,nil];

[alert show];

[alert release];

}

searchText.text=@"";

}

原文链接:https://www.f2er.com/regex/363112.html

猜你在找的正则表达式相关文章