views:

233

answers:

1

Hi to all,

My application creates a SharePoint site and an Active Directory group from user input. Special characters that are mentioned in http://www.webmonkey.com/reference/Special_Characters becomes a big problem in my application. Application creates group names differently and application can't access them from name property. I want the user input to be validated from a regular expression for these characters. I googled in and found some good regex sampler and testers but they won't solve my problem. So can anybody suggest a regex for disallowing special characters which is a problem for Active Directory object names?

P.S. Application users may enter Turkish inputs, so regex should also allow Turkish characters like 'ç', 'ş', 'ö'

+1  A: 

You should start with something like this:

^(\p{L}|\p{N}|\p{P})+$

This will match:

  • \p{L}: any kind of letter from any language
  • \p{N}: any kind of numeric character in any script
  • \p{P}: any kind of punctuation character.

When you query your AD, you must to escape some special characters, described here: Creating a Query Filter

If any of the following special characters must appear in the query filter as literals, they must be replaced by the listed escape sequence.

  ASCII     Escape sequence 
character     substitute
    *           "\2a"
    (           "\28"
    )           "\29"
    \           "\5c"
   NUL          "\00"

In addition, arbitrary binary data may be represented using the escape sequence syntax by encoding each byte of binary data with the backslash followed by two hexadecimal digits. For example, the four-byte value 0x00000004 is encoded as "\00\00\00\04" in a filter string.

Rubens Farias
Thanks! Problem solved:)
Melih Öztürk