12

Sitecore constructs the default URL of an item based on its 'name' and it can also be configured to use 'Display Name' instead.

There are Sitecore routines that prevent the content editor from typing Special characters on item names however, any character can be typed on a Display Name.

I have a scenario where the website has 3 languages and the URLs are built based on DisplayNames (useDisplayName set to true).

<patch:attribute name="useDisplayName">true</patch:attribute> 

The content editors have been typing characters like áêã so I am creating my own routine to remove the special characters.

These characters are obviously not desired on a URL so that led me to think...

Is there a Sitecore routine or configuration that could prevent the user to type special characters on Display Name or all developers out there need to develop their own routine?

Thanks

2 Answers 2

7

Following up on Mark's answer, if you wanted to do just use a regex you could use the following steps:

  1. Go to /sitecore/system/Settings/Validation Rules/Field Rules/
  2. Create a folder called Custom
  3. Create an item called Is Valid Display Name based on the template /sitecore/templates/System/Validation/Validation Rule
  4. Set the field appropriately. Type should be Sitecore.Data.Validators.FieldValidators.RegexValidator,Sitecore.Kernel and the parameters should be something like Pattern=^[\w*$][\w-$]*((\d{1,})){0,1}$&Text=Field "{0}" is not a valid display name.&Result=FatalError
  5. Add the new validator to the __Display name field's Validator Bar field

The regex pattern was pulled from the setting ItemNameValidation with the \s removed. Adding it to the validator bar will prevent the user from being able to save an item with an illegal display name.

You might want to also take into account other checks that are done against item names. These settings come to mind as an example of that: InvalidItemNameChars, AllowDuplicateItemNamesOnSameLevel, and ItemNameAllowMixingReplacementCharacters. If something more complicated like this is needed you may need multiple validators or a custom validator that can tie it all together.

6

Display Name is a field. As such, you can enforce its value using normal Sitecore validation and workflow tools.

I am by no means a specialist in writing RegEx expressions, but I'm pretty sure you can arrive at what you need by setting one such validator up for your Display Name field.

It will only work on new changes however; the content your authors have already put into Display Name will have to be cleaned up; using code or perhaps SPE scripting.

Additional info:

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.