检查变音符号与常规的前pression [英] Checking for diacritics with a regular expression

查看:169
本文介绍了检查变音符号与常规的前pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的问题:现有的项目让我增加额外的字段(对这些领域的常规EX pressions额外的检查),以支持自定义输入表单。我需要添加一个新的形式,但不能改变这个项目如何工作的。这种形式可以让访问者进入他的名字和姓氏的首字母加。所以,正则表达式 ^ [A-ZA-Z] * $ 现在的工作只是罚款。
这时有人注意到它不会接受读音符号字符的输入。如Ömür A土耳其的名字没有被接受为有效。它需要被接受,尽管

Simple problem: an existing project allows me to add additional fields (with additional checks on those fields as regular expressions) to support custom input forms. And I need to add a new form but cannot change how this project works. This form allows a visitor to enter his first and last name plus initials. So the RegEx ^[a-zA-Z.]*$ worked just fine for now.
Then someone noticed that it wouldn't accept diacritic characters as input. A Turkish name like Ömür was not accepted as valid. It needs to be accepted, though.

所以,我有两个选择:

  1. 完全拆下检查,这将允许用户进入垃圾。
  2. 在写一个正前pression,这也将包括音调符号的字母,但仍然没有数字,空格或其他非字母。

既然我不能改变这个项目的code,我只有这两种选择。我想preFER选项2,但现在不知道正确的正则表达式应该是。 (该项目是用C#4.0。)

Since I cannot change the code of the project, I only have these two options. I would prefer option 2 but now wonder what the proper RegEx should be. (The project is written in C# 4.0.)

推荐答案

您可以使用特定的UNI code转义的字母 - \ p {L〕(这将包括 A-ZA-Z 的取值范围):

You can use the specific Unicode escape for letters - \p{L} (this will include the A-Za-z ranges):

^[.\p{L}]*$

查看 regularex pressions.info

\ p {L〕或\ p {}信

\p{L} or \p{Letter}

匹配具有财产信一个统一code code点。查看教程中的Uni code字符属性属性的完整列表。每个统一code code点有且只有一个属性。可使用的字符类中。

Matches a single Unicode code point that has the property "letter". See Unicode Character Properties in the tutorial for a complete list of properties. Each Unicode code point has exactly one property. Can be used inside character classes.

这篇关于检查变音符号与常规的前pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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