private bool ValidateRequired(Ctrl ctrl) { var c = (RequiredCtrl)ctrl; string val = GetText(c.source); if (!string.IsNullOrEmpty(val)) { SetText(c.target, string.Empty); return true; } if (string.IsNullOrEmpty(c.msg)) SetText(c.target, c.name + " is required."); else SetText(c.target, c.msg); return false; }
private bool validateRegex(Ctrl ctrl) { var c = (RegexCtrl)ctrl; string val = GetText(c.source); if (Regex.IsMatch(c.Regexp, val)) { SetText(c.target, string.Empty); return true; } if (string.IsNullOrEmpty(c.msg)) SetText(c.target, c.name + " is in invalid format."); else SetText(c.target, c.msg); return false; }
private bool validateCustom(Ctrl ctrl) { var c = (CustomCtrl)ctrl; if (c.test(c)) { SetText(c.target, string.Empty); return true; } SetText(c.target, c.msg); return false; }
private bool ValidateRange(Ctrl ctrl) { var c = (RangeCtrl)ctrl; string val = GetText(c.source); if (!(val.Length < c.min || val.Length > c.max)) { SetText(c.target, string.Empty); return true; } if (string.IsNullOrEmpty(c.msg)) SetText(c.target, c.name + "'s length is out of specified range."); else SetText(c.target, c.msg); return false; }
public void Set(Ctrl[] cs) { foreach (var c in cs) { if (c is RequiredCtrl) c.Validate = ValidateRequired; else if (c is RangeCtrl) c.Validate = ValidateRange; else if (c is RegexCtrl) c.Validate = validateRegex; else if (c is CustomCtrl) c.Validate = validateCustom; } this.cs = cs; msgs = new List<string>(cs.Length); }