public static ValidatorContainer <T> IsNumber <T>(this ValidatorContainer <T> container, float?min, float?max, bool stopWhileFail) { if (container == null) { return(null); } min = min ?? float.MinValue; max = max ?? float.MaxValue; float tryFloat; if (!float.TryParse(container.ValidatorObject.ToString(), out tryFloat) || tryFloat < (float)min || tryFloat > (float)max) { string errorMessage = string.Format("请输入正确的{0}", container.ValueName); container.AddError(errorMessage); if (stopWhileFail) { return(null); } } return(container); }
public static ValidatorContainer <T> Exclude <T>(this ValidatorContainer <T> container, string[] excludeStrings, bool stopWhileFail) { if (container == null) { return(null); } foreach (var str in excludeStrings) { if (container.ValidatorObject.ToString().Contains(str)) { string charts = string.Join(",", excludeStrings).Replace(" ", "空格").Replace(" ", "全角空格"); string errorMessage = string.Format("{0}中包含了不允许使用的特殊字符:{1}", container.ValueName, str); container.AddError(errorMessage); if (stopWhileFail) { return(null); } } return(container); } return(container); }