如何使用C#只检查大写字母和数字,符号? [英] How to check only capital letter and numbers, symbols using C#?

查看:80
本文介绍了如何使用C#只检查大写字母和数字,符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证数据表value.i使用行和列从数据表中获取值,并将值存储在一个变量中,如'z',现在我想验证它只包含

*大写字母

*符号

*数字



我尝试过:



i want to validate the data table value.i get the value from data table using row and column and stored the value in one variable like 'z' now i want to validate this contain only
*capital letter
*symbols
*numbers

What I have tried:

if (z.Any(char.IsUpper) && z.Any(char.IsSymbol) && z.Any(char.IsDigit))
{
//statement
}
else







但它不起作用。 :(




but it is not working. :(

推荐答案

string text = "


Apple20;
// 检查所有3个案例
if (text.Any( char .IsUpper)&& text.Any( char .IsSymbol)&& text。任何( char .IsDigit))
{
// 文本包含大写,符号和数字
}

// 检查任何人包含
if (text.Any( char) .IsUpper)|| text.Any( char .IsSymbol)|| text.Any( char .IsDigit))
{
// text包含大写或符号或数字
}
Apple20"; // to check all 3 cases if (text.Any(char.IsUpper) && text.Any(char.IsSymbol) && text.Any(char.IsDigit)) { // text contains upper case, symbol and number } // to check anyone contains if (text.Any(char.IsUpper) || text.Any(char.IsSymbol) || text.Any(char.IsDigit)) { // text contains upper case or symbol or number }


我建​​议使用< a href =https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.ismatch(v=vs.110).aspx> Regex.IsMatch [ ^ ]方法与 Linq To DataSet [ ^ ] 。



看看例子:



I'd suggest to use Regex.IsMatch[^] method together with Linq To DataSet[^].

Take a look at example:

DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("text", typeof(string)));
dt.Rows.Add(new object[]{"


这篇关于如何使用C#只检查大写字母和数字,符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆