From 807df434f63ec3341fe909592bd2c47c4cff98e4 Mon Sep 17 00:00:00 2001 From: yawka Date: Thu, 7 Nov 2013 18:39:02 +0200 Subject: [PATCH 1/2] Add validation for regular expression property --- src/Umbraco.Core/Models/PropertyType.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Core/Models/PropertyType.cs b/src/Umbraco.Core/Models/PropertyType.cs index 3b4915862a..cfeb9e832d 100644 --- a/src/Umbraco.Core/Models/PropertyType.cs +++ b/src/Umbraco.Core/Models/PropertyType.cs @@ -361,8 +361,16 @@ namespace Umbraco.Core.Models //Check against Regular Expression for Legacy DataTypes - Validation exists and value is not null: if(string.IsNullOrEmpty(ValidationRegExp) == false && (value != null && string.IsNullOrEmpty(value.ToString()) == false)) { - var regexPattern = new Regex(ValidationRegExp); - return regexPattern.IsMatch(value.ToString()); + try + { + var regexPattern = new Regex(ValidationRegExp); + return regexPattern.IsMatch(value.ToString()); + } + catch + { + throw new Exception(string .Format("Invalid validation expression on property {0}",this.Alias)); + } + } //TODO Add PropertyEditor validation when its relevant to introduce From e0a10080b1d69eb1e701d187e6a3f571facc2731 Mon Sep 17 00:00:00 2001 From: yawka Date: Thu, 7 Nov 2013 18:39:27 +0200 Subject: [PATCH 2/2] Add UI validation for regular expression property --- .../GenericProperties/GenericProperty.ascx | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Web.UI/umbraco/controls/GenericProperties/GenericProperty.ascx b/src/Umbraco.Web.UI/umbraco/controls/GenericProperties/GenericProperty.ascx index 4cdad45578..bd20a7d269 100644 --- a/src/Umbraco.Web.UI/umbraco/controls/GenericProperties/GenericProperty.ascx +++ b/src/Umbraco.Web.UI/umbraco/controls/GenericProperties/GenericProperty.ascx @@ -25,33 +25,34 @@ Edit "" - - + + - + - + - + - + - +
+
Search for a regular expression
- +
@@ -69,4 +70,13 @@ duplicatePropertyNameAsSafeAlias('<%=tbName.ClientID%>', '<%=tbAlias.ClientID%>'); } }); + function ValidateValidation(sender, args) { + try { + var patt = new RegExp(args.Value); + args.IsValid = true; + + } catch (e) { + args.IsValid = false; + } + } \ No newline at end of file