GibboK
GibboK

Reputation: 73988

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 not in certain Unicode Categories.

Designation:

Upvotes: 0

Views: 136

Answers (2)

Richard Szalay
Richard Szalay

Reputation: 84784

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.

Upvotes: 2

Heinzi
Heinzi

Reputation: 172408

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

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

Upvotes: 1

Related Questions