Validate Youtube url in sitecore

103 Views Asked by At

I'm new with sitecore 9.0 and want to add validation on a field to check if the value entered in this field is only youtube url , I know that it must match regular expression but how to add this in sitecore ?? any help will be appreciated

1

There are 1 best solutions below

1
On BEST ANSWER

First of all you have to create a new validation rule and then apply it to your field at a data template level. For example, if you want to validate your numeric value by a regular expression like ^(\d{6,12})$ then you will need to:

  1. Create a new Validation Rule in /sitecore/system/Settings/Validation Rules/Field Rules/ folder with Sitecore.Data.Validators.FieldValidators.RegexValidator,Sitecore.Kernel Type and specify your regular expression in Parameters field see an example here

  2. Apply the validation rules to the required field by selecting your newly created Validation Rule in Quick Action Bar, Validate Button, Validator Bar properties under the Validation Rules section for your specific field in the corresponding data template see an example here

From now on you can validate your data input during editing, for example via Preview -> Validation action in Sitecore menu.