public static bool StringLength(string str, validator model) { if (string.IsNullOrEmpty(str)) { return(true); } bool isAccord = true; if (!string.IsNullOrEmpty(model.maxlength)) { if (str.Length > int.Parse(model.maxlength)) { isAccord = false; } } if (!string.IsNullOrEmpty(model.minlength)) { if (str.Length < int.Parse(model.minlength)) { isAccord = false; } } return(isAccord); }
public static bool RegularExpression(string str, validator model) { if (string.IsNullOrEmpty(str)) { return(true); } Regex regex = new Regex(model.art); return(regex.IsMatch(str)); }
public static bool Required(string str, validator model) { if (string.IsNullOrEmpty(str)) { return(false); } else { return(true); } }
public static bool Range(string str, validator model, string type) { if (string.IsNullOrEmpty(str)) { return(true); } bool isAccord = true; switch (type) { case "Double": Double d; isAccord = Double.TryParse(str, out d); if (!isAccord) { break; } if (!string.IsNullOrEmpty(model.maxvalue)) { isAccord = double.Parse(model.maxvalue) > d; if (!isAccord) { break; } } if (!string.IsNullOrEmpty(model.minvalue)) { isAccord = double.Parse(model.minvalue) < d; } break; case "int": int i; isAccord = int.TryParse(str, out i); if (!isAccord) { break; } if (!string.IsNullOrEmpty(model.maxvalue)) { isAccord = int.Parse(model.maxvalue) > i; if (!isAccord) { break; } } if (!string.IsNullOrEmpty(model.minvalue)) { isAccord = int.Parse(model.minvalue) < i; } break; case "DateTime": DateTime dt; isAccord = DateTime.TryParse(str, out dt); if (!isAccord) { break; } if (!string.IsNullOrEmpty(model.maxvalue)) { isAccord = DateTime.Parse(model.maxvalue) > dt; if (!isAccord) { break; } } if (!string.IsNullOrEmpty(model.minvalue)) { isAccord = DateTime.Parse(model.minvalue) < dt; } break; default: break; } return(isAccord); }