Let's start with your Note -
I cannot add it on the field level as the template is shared across multiple items.
You will need to create a separate field for this because a field validation can be applied to a field only, otherwise, you need to add some custom save action.
Now come to the second point, the answer provided by Yogesh is technically correct but when Sitecore gives you the OOTB feature you don't need to create any custom validation for this.
Sitecore gives IntegerRangeValidator
and RegexValidator
, the examples of these types are -
- IntegerRangeValidator - /sitecore/system/Settings/Validation Rules/Field Rules/Sample/Rating 1 to 9
- RegexValidator - /sitecore/system/Settings/Validation Rules/Field Rules/Common/Is Email
You can use any of these for validating the field, all you need to copy one of them and update them accordingly. I am using IntegerRangeValidator
here in this example -

Make sure to add type should be - Sitecore.Data.Validators.FieldValidators.IntegerRangeValidator,Sitecore.Kernel
and parameter should contain Result=FatalError
with min and max value- Min=1&Max=5&Result=FatalError
.
Important - this validation is applicable for integer
type of field so make sure your field type should be an integer
If you don't want to use integer
type then you can use Sitecore.Data.Validators.FieldValidators.RegexValidator,Sitecore.Kernel
as type and parameter - Pattern=YOURREGEX&Result=FatalError&Text=Field "{0}" is not a valid Range.