我目前正在尝试分别验证 C# 上的 2 个文本框的名字和姓氏,但问题是文本需要使用西里尔字母。这是我到目前为止所拥有的
string expression = "^[\u0410-\u042F][\u0430-\u044f]{2-20}$";
if (System.Text.RegularExpressions.Regex.IsMatch(textBox1.Text, expression) &&
System.Text.RegularExpressions.Regex.IsMatch(textBox2.Text, expression))
MessageBox.Show("Correct","");
else
MessageBox.Show("There was a mistake in the names.", "Error");
每个名称的第一个字母应为大写,其他字母均为小写,因此西里尔字母的 Unicode 表示大写和小写。像这样,它给了我“其他”选项,我不知道错误可能在哪里。
最佳答案
更改{2-20}
至{2,20}
{n,m}
Matches at least
n
and at mostm
times.n
andm
are nonnegative integers, wheren <= m
. There cannot be a space between the comma and the numbers.
关于c# - 西里尔文文本验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34417102/