/// <summary> /// Converts Mask string to Regex. /// </summary> /// <param name="value"></param> /// <param name="targetType"></param> /// <param name="parameter"></param> /// <param name="culture"></param> /// <returns></returns> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is not null && !string.IsNullOrEmpty(value.ToString())) { return(RegexUtility.MaskToRegexConverter(value.ToString())); } return(null); }
/// <summary> /// Initializes a new instance of the <see cref="EditableComboViewModel"/> class. /// </summary> /// <param name="context">The context.</param> /// <param name="commonServices">The common services.</param> /// <param name="loggerFactory">The logger factory.</param> public EditableComboViewModel( IContext context, IBaseCommonServices commonServices, ILogger <EditableComboViewModel> loggerFactory) : base(context, commonServices, loggerFactory) { MaskExpression = "9999aa"; RegexExpression = "0000>LL"; //1111Ab 0000Xx this.Validator = new Action <IObservableClass>(_ => { var regex = RegexUtility.MaskToRegexConverter(RegexExpression); if (string.IsNullOrEmpty(RegexSample) || !regex.IsMatch(RegexSample)) { Properties[nameof(RegexSample)].Errors.Add("TextSample is fout."); } }); }
public void MaskToRegexDoNotMatchTest(string mask, string value) => Assert.IsFalse(RegexUtility.MaskToRegexConverter(mask).IsMatch(value));