//TODO public static ValidationResult DateNullCheckRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); if (isValid(target)) { result.Success = (new SimpleDate(target)).isValidDate(); } result.ErrorMessage = "Please specify both To and From dates."; return result; }
public static ValidationResult DateRangeRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); if (isValid(target)) { SimpleDate dt0 = new SimpleDate(target); SimpleDate dt1 = new SimpleDate(rule.min); SimpleDate dt2 = new SimpleDate(rule.max); result.Success = dt0.compare(dt1) >= 0 && dt0.compare(dt2) <= 0; } result.ErrorMessage = "DateRangeRule violation."; return result; }
public static object Validate(Type type, string method, object [] args) { object obj = Activator.CreateInstance(type); MethodInfo info = type.GetMethod(method); if (info != null) { return info.Invoke(obj, BindingFlags.InvokeMethod, null, args, null); } else { ValidationResult result = new ValidationResult(); result.ErrorMessage = "Validation rule " + method + " is not available."; return result; } }
public static ValidationResult RegularExpressionValidationRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); if (isValidId(id) && cnt > 0) { result.Success = true; } else if (isValid(target)) { Regex regex = new Regex(rule.regex); MatchCollection mc = regex.Matches(target); result.Success = mc.Count > 0; } result.ErrorMessage = "Please enter this value in the format requested: " + rule.regex; return result; }
public static ValidationResult PrecisionRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); if (isValidId(id) && cnt > 0) { result.Success = true; } else if (isNumber(target) != 0) { result.Success = true; } result.ErrorMessage = "PrecisionRule violation."; return result; }
public static ValidationResult NumberSeparatorNotAllowedRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); if (isValidId(id) && cnt > 0) { result.Success = true; } else if (isValid(target)) { target = target.Trim(); if (target.StartsWith("-")) { target = target.Substring(1, target.Length - 1); } target = target.Trim(); char [] ca = target.ToCharArray(); int len = ca.Length; int i = 0; bool success = true; while (success && i < len) { success = char.IsDigit(ca[i]); i ++; } result.Success = success; } result.ErrorMessage = "Please enter only numeric digits with no symbols."; return result; }
public static ValidationResult MultiSelectMinNumberValuesRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); try { result.Success = cnt > int.Parse(rule.min); } catch(Exception) { } result.ErrorMessage = "Please make no fewer than [" + rule.min + "] selections."; return result; }
public static ValidationResult UrlValidationRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); if (isValidId(id) && cnt > 0) { result.Success = true; } else if (isValid(target)) { result.Success = checkUri(target, rule.protocol, rule.invalidhost, rule.invalidhostoverride); } else result.Success = true; result.ErrorMessage = "UrlValidationRule violation."; return result; }
public static ValidationResult StringLengthRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); if (isValidId(id)) { result.Success = true; // cnt > 0; result.ErrorMessage = "Please select a valid item."; } else if (isValid(target)) { int len = target.Length; result.Success = (0 < len && len <= rule.length); result.ErrorMessage = "Please enter no more than [" + rule.length + "] character(s)."; } else { result.Success = true; } return result; }
public static ValidationResult MaxDoubleValidationRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); if (isValidId(id) && cnt > 0) { result.Success = true; } else if (isValid(target)) { try { result.Success = double.Parse(target) < double.Parse(rule.max); } catch(Exception) { } } result.ErrorMessage = "Please enter a value less than [" + rule.max + "]."; return result; }
public static ValidationResult MaskCheckRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); if (isValidId(id) && cnt > 0) { result.Success = true; } else if (isValid(target)) { char [] valArray = target.ToCharArray(); char [] maskArray = rule.mask.ToCharArray(); int len = valArray.Length; bool success = len != maskArray.Length; if (success) { char val; char mask; for(int i=0; i<len && success; i++) { val = valArray[i]; mask = maskArray[i]; switch(mask) { case 'X': // The value must be a number success = char.IsDigit(val); break; case 'A': // the value must be a letter success = char.IsLetter(val); break; default: // these characters must match success = val == mask; break; } } } result.Success = success; } result.ErrorMessage = "Please enter this value in the format requested."; return result; }
public static ValidationResult IntRangeValidationRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); if (isValidId(id) && cnt > 0) { result.Success = true; } else if (isValid(target)) { try { double val = double.Parse(target); result.Success = (val >= int.Parse(rule.min)) && (val <= int.Parse(rule.max)); } catch(Exception) { } } result.ErrorMessage = "Please enter an value between [" + rule.min + "] and [" + rule.max + "]."; return result; }
public static ValidationResult DoubleRangeValidationRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); if (isValidId(id) && cnt > 0) { result.Success = true; } else if (isValid(target)) { try { double d = double.Parse(target); result.Success = double.Parse(rule.min) <= d && d <= double.Parse(rule.max); } catch(Exception) { //Data parsing error } } else result.Success = true; // null is okay result.ErrorMessage = "Please enter a value between [" + rule.min + "] and [" + rule.max + "]."; return result; }
public static ValidationResult DateValidationRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); if (isValid(target)) { int full = rule.full; result.Success = checkDate(target, full); } result.ErrorMessage = "Argument must be a valid date."; return result; }
public static ValidationResult RequiredRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); result.Success = cnt > 0; result.ErrorMessage = "RequiredRule violation."; return result; }
//TODO public static ValidationResult SimpleRuleSetRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); if (isValidId(id) && cnt > 0) { result.Success = true; } else { result.Success = true; } return result; }
public static ValidationResult MinIntValidationRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); if (isValidId(id) && cnt > 0) { result.Success = true; } else if (isValid(target)) { try { double val = double.Parse(target); result.Success = val > int.Parse(rule.min); } catch(Exception) { } } result.ErrorMessage = "Please enter an value greater than [" + rule.min + "]."; return result; }
public static ValidationResult ThousandsSeparatorNotAllowedRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); if (isValidId(id) && cnt > 0) { result.Success = true; } else if (isValid(target)) { string separator = rule.separator; result.Success = target.IndexOf(separator) == -1; } result.ErrorMessage = "Please enter a number with no thousands separators."; return result; }
public static ValidationResult MotorUKValidationRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); if (isValidId(id) && cnt > 0) { result.Success = true; } else if (isValid(target)) { result.Success = checkUKVin(target); } return result; }
public static ValidationResult VinValidationRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); if (isValidId(id) && cnt > 0) { result.Success = true; } else if (isValid(target)) { int year = 1981; // TODO! result.Success = checkVin(target, year); } return result; }
public static ValidationResult MultiSelectMinMaxNumberValuesRule(int id, int cnt, string target, ValidationRule rule) { ValidationResult result = new ValidationResult(); result.Success = int.Parse(rule.min) < cnt && cnt < int.Parse(rule.max); result.ErrorMessage = "Please make between [" + rule.min + "] and [" + rule.max + "] selections."; return result; }