c# - 西里尔文文本验证

标签 c# regex validation

我目前正在尝试分别验证 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 most m times. n and m are nonnegative integers, where n <= m. There cannot be a space between the comma and the numbers.

source

关于c# - 西里尔文文本验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34417102/

相关文章:

regex - Perl:我可以在文本中使用的变量中使用捕获组来替换正则表达式吗?

java - 在字符类中使用 $ anchor 不起作用

javascript - 表单验证在 Metronic 中无法正常工作

python - 如何在没有 try/except 或 str.isdigit 的情况下检查字符串是否包含数字?

c# - 使用 JavaScriptSerializer() 反序列化 JSON 文件

c# - 为什么我的 NLog 配置不能在我的服务器机器上运行?

c# - 使用 Json.net 将大量数据流式传输为 JSON 格式

c# - X文档 : get the first child element of type 'a' or 'b'

javascript - 用于解析类似 jQuery 选择器的字符串的正则表达式

php - 拉拉维尔 5.4 : How do I validate an image size?