[Fixes #6704] Regular Expression for Validating TextField Element (#6705)

Fixes #6704
This commit is contained in:
Sergio Navarro 2016-10-13 21:10:57 +02:00 committed by Sébastien Ros
parent 03d5a375d3
commit b8bd587a9f
3 changed files with 13 additions and 0 deletions

View File

@ -59,6 +59,12 @@ namespace Orchard.DynamicForms.Drivers {
Title: "Maximum Length",
Classes: new[] { "text", "medium" },
Description: T("The maximum length allowed.")),
_ValidationExpression: shape.Textbox(
Id: "ValidationExpression",
Name: "ValidationExpression",
Title: "Validation Expression",
Classes: new[] { "text", "large" },
Description: T("The regular expression the text must match with.")),
_CustomValidationMessage: shape.Textbox(
Id: "CustomValidationMessage",
Name: "CustomValidationMessage",

View File

@ -5,5 +5,6 @@ namespace Orchard.DynamicForms.Validators.Settings {
public bool? IsRequired { get; set; }
public int? MinimumLength { get; set; }
public int? MaximumLength { get; set; }
public string ValidationExpression { get; set; }
}
}

View File

@ -23,6 +23,12 @@ namespace Orchard.DynamicForms.Validators {
r.ErrorMessage = settings.CustomValidationMessage;
});
}
if (!string.IsNullOrWhiteSpace(settings.ValidationExpression)) {
yield return _validationRuleFactory.Create<RegularExpression>(r => {
r.Pattern = settings.ValidationExpression;
r.ErrorMessage = settings.CustomValidationMessage;
});
}
}
}
}