UPN without special character and space


How would I get it to create a UPN without space and special character?


First Name: John
Last Name: O’Neal Montanerioalcatrez

We want it to create the username like the following, First Letter of FirstName only and 19 letters of the last name with no special character, and space.

so it be like this for the UPN: JONealMontanerioalcat

*NOTE: If the 19 letter of last name is not viable then how would we remove space and special character from last name atleast.

Please take a look at our special methods which can be used to achieve your required result:


These methods can be used to strip white space and special characters.

Take a look at the RemoveWhiteSpaceSpecialCharactersDiacritics() method.

You can combine this with other logic to get the string length you need.

Here is an example:

(Person.PreferredName + ‘.’ + Person.LastName).RemoveWhiteSpaceSpecialCharactersDiacritics().Length < 19? (Person.PreferredName + ‘.’ + Person.LastName).RemoveWhiteSpaceSpecialCharactersDiacritics():(Person.PreferredName + ‘.’ + Person.LastName).RemoveWhiteSpaceSpecialCharactersDiacritics().Substring(0,19)

This expression concats the names and then calls the RemoveWhiteSpaceSpecialCharactersDiacritics method to remove white space and special chars.

It also uses a c# ternary expression to check the final length, if its less than 19 chars, then it returns the full string, if its more than 19 chars, it will only return the first 19 chars.

I think this will work for you.


what does the “0” mean at the (0,19)?

(Person.PreferredName + ‘.’ + Person.LastName).RemoveWhiteSpaceSpecialCharactersDiacritics().Substring(0,19)

I get this error.

The 0 in the Substring states start at the 0 index character (the first character)…then take the next 19 characters.

Please replace the single quotes.

When you copy and paste the expression we posted , it somehow replaces the single quotes with something else

what do I replace the single quotes with?

Replace them with your own single quotes.

The ones we have pasted are not single quotes (they are accents).

this dont work when I add to a working variable.


this works:

Please change it to Person.LastName.Replace(“”, " ")

Replace the double-quotes as it will paste it as an accent rather than a proper double-quote

that seams to work, how would I add to remove special character along with spaces?

Please take a look at this document for some special methods that will help you


I did. the following dont work. I already showed a screenshot it didnt work.


Please make suet that you are using the latest version of Connect to AD.

that seem to have done the trick!!!

tyvm Vanessa!