2017-10-04 54 views

回答

3

你可以使用LINQ:

if (StringName.Text.Any(Char.IsLetter)) 
{ 
    // Do something 
} 
+3

很奇怪,没有人提出任何接近你之前这个答案...也许[另一个宇宙(https://stackoverflow.com/a/12884682/477420 )... –

2

尝试的LINQ。如果您接受任何 Unicode的信,说,俄罗斯ъ

if (StringName.Text.Any(c => char.IsLetter(c))) 
{ 
    // Do Something 
} 

如果你只想a..z以及A..Z

if (StringName.Text.Any(c => c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')) 
{ 
    // Do Something 
} 

最后,如果你坚持正则表达式

if (Regex.IsMatch(StringName.Text, @"\p{L}")) 
{ 
    // Do Something 
} 

或(第二选项) a..z以及A..Z字母只

if (Regex.IsMatch(StringName.Text, @"[a-zA-Z]")) 
{ 
    // Do Something 
} 
相关问题