public static IRule NumberRangeValidation(string propname, byte intPartLength, ValidationSeverity severity = ValidationSeverity.Critical) { decimal number; if (intPartLength == 0) { number = 0.9999999999999999999999999999M; } else { string numStr = ""; for (byte i = 1; i <= intPartLength; i++) { numStr += "9"; } numStr = numStr + "."; numStr = numStr.PadRight(29, '9'); number = System.Convert.ToDecimal(numStr); } ValueRangeValidationHelper range = new ValueRangeValidationHelper((number * -1), number); ClientSideValidationRule <IComparable, ValueRangeValidationHelper> newValidation; newValidation = new ClientSideValidationRule <IComparable, ValueRangeValidationHelper>("Number Range", "Number must be between " + (number).ToString() + " and " + (number * -1).ToString() + ".", propname, CommonPropRuleHandlers.BetweenValueHandler); newValidation.AllowedValue = range; newValidation.Severity = severity; return(newValidation); }
public static bool BetweenValueHandlerAllowMinValue(IPropertyRule <IComparable, ValueRangeValidationHelper> target, object objectChecked) { if (target.AllowedValue == null) { return(false); } ValueRangeValidationHelper valRange = target.AllowedValue; IComparable val = target.PropertyValue(objectChecked); return(!val.Between(valRange.FromValue, valRange.ToValue)); }