The issue I can see is that you are using FieldValidators
under the type i.e. Sitecore.Data.Validators.FieldValidators.RegexValidator,Sitecore.Kernel
And the logic for this validator checks for the field.
string controlValidationValue = this.ControlValidationValue;
if (string.IsNullOrEmpty(controlValidationValue))
return ValidatorResult.Valid;
string parameter = this.Parameters["Pattern"];
if (string.IsNullOrEmpty(parameter) || new Regex(parameter, RegexOptions.IgnoreCase).IsMatch(controlValidationValue))
return ValidatorResult.Valid;
this.Text = this.GetText("The field \"{0}\" does not match the regular expression \"{1}\".", this.GetFieldDisplayName(), parameter);
return this.GetFailedResult(ValidatorResult.Error);
So you should create a new validator class and use it in your validation rule by passing the class and assembly name in the Type field. Here is an example of OOTB validator that is checking the encoded character.
Item obj = this.GetItem();
if (obj == null || !obj.Paths.IsContentItem)
return ValidatorResult.Valid;
string name = obj.Name;
string displayName = obj.DisplayName;
if (this.ContainsEncodedAndDecodedSymbols(name))
{
this.Text = this.GetText(Translate.Text("The item name contains both encoded characters and characters that are used to replace encoded characters when Sitecore generates an item URL."));
return this.GetFailedResult(ValidatorResult.Error);
}
if (!this.ContainsEncodedAndDecodedSymbols(displayName))
return ValidatorResult.Valid;
this.Text = this.GetText(Translate.Text("The item display name contains both encoded characters and characters that are used to replace encoded characters when Sitecore generates an item URL."));
return this.GetFailedResult(ValidatorResult.Error);
So you need to use the code that is given in the RegexValidator
class and pass the name of the item, not the field.
And it will solve your issue.