开发者

How can I detect characters that are not in a specific Unicode category?

I use ASP.NET 4 and C#.

I need to apply a RegEx to an RegularExpressionValidator control to NOT allow inserting in a TextBox of charters that are 开发者_JS百科not in certain Unicode Categories.

Designation:

  • UppercaseLetter
  • LowercaseLetter


You can use \p{CLASS} to match unicode character classes:

[\p{UppercaseLetter}\p{LowercaseLetter}]

See the "Supported Unicode General Categories" and "Supported Named Blocks" sections of the Character Classes page on MSDN for a list of supported character classes.

See also this question: Regular expression to catch letters beyond a-z

Edit: Keep in mind that this won't work in the browser as I don't think the client implementations of Regex support /p.


I don't think it can be done using a RegularExpressionValidator.

An obvious solution would be to use a CustomValidator that checks Char.GetUnicodeCategory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜