0

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:

  • UppercaseLetter
  • LowercaseLetter
dlras2
  • 8,416
  • 7
  • 51
  • 90
GibboK
  • 71,848
  • 143
  • 435
  • 658

2 Answers2

2

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.

Community
  • 1
  • 1
Richard Szalay
  • 83,269
  • 19
  • 178
  • 237
1

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

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

Heinzi
  • 167,459
  • 57
  • 363
  • 519