From 9606cab81e2b56542fdfca28960227260d4469a9 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 23 Jul 2015 14:44:02 +0200 Subject: [PATCH] Fixes: U4-4669 Required checkbox is overruled by regex on document type --- .../Filters/ContentItemValidationHelper.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web/WebApi/Filters/ContentItemValidationHelper.cs b/src/Umbraco.Web/WebApi/Filters/ContentItemValidationHelper.cs index 239b9bd576..88eda3c64e 100644 --- a/src/Umbraco.Web/WebApi/Filters/ContentItemValidationHelper.cs +++ b/src/Umbraco.Web/WebApi/Filters/ContentItemValidationHelper.cs @@ -152,10 +152,26 @@ namespace Umbraco.Web.WebApi.Filters if (p.ValidationRegExp.IsNullOrWhiteSpace() == false) { - foreach (var result in p.PropertyEditor.ValueEditor.RegexValidator.Validate(postedValue, p.ValidationRegExp, preValues, editor)) + + //We only want to execute the regex statement if: + // * the value is null or empty AND it is required OR + // * the value is not null or empty + //See: http://issues.umbraco.org/issue/U4-4669 + + var asString = postedValue as string; + + if ( + //Value is not null or empty + (postedValue != null && asString.IsNullOrWhiteSpace() == false) + //It's required + || (p.IsRequired)) { - actionContext.ModelState.AddPropertyError(result, p.Alias); + foreach (var result in p.PropertyEditor.ValueEditor.RegexValidator.Validate(postedValue, p.ValidationRegExp, preValues, editor)) + { + actionContext.ModelState.AddPropertyError(result, p.Alias); + } } + } }