dotnet/aspnetcore · error · Error
Range validator requires at least one of "min" or "max"…
Error message
Range validator requires at least one of "min" or "max" parameters.
What it means
The Range validator (client-side counterpart of [Range(min,max)]) requires at least one bound — min or max — to be defined; a range rule with neither bound has no effect. The validator throws if both params.min and params.max are undefined rather than silently passing every value. Non-numeric inputs fail; missing bounds is a configuration error.
Solutions
- Ensure the input renders data-val-range-min and/or data-val-range-max with numeric values.
- Confirm the C# property has [Range(1, 100)] (or with only min/max) so the tag helper emits the attributes.
- If registering manually, pass { min: '1', max: '100' } (at least one) in params.
- Verify no HTML sanitizer is stripping data-val-range-* attributes.
Example fix
<!-- before --> <input name="Age" data-val="true" data-val-range="Out of range" /> <!-- after --> <input name="Age" data-val="true" data-val-range="Out of range" data-val-range-min="18" data-val-range-max="120" />
Defensive patterns
Strategy: validation
Validate before calling
function rangeConfigured(params: any): boolean {
return !!params && (params.min !== undefined || params.max !== undefined);
} Type guard
function hasRangeBound(p: unknown): boolean {
return !!p && ((p as any).min !== undefined || (p as any).max !== undefined);
} Prevention
- Use [Range(min, max)] on the model so tag helpers emit data-val-range-min/-max.
- Confirm rendered inputs include at least one bound attribute.
- Ensure HTML sanitizers preserve data-val-range-* attributes.
- Pass at least one bound when registering the validator manually.
When it happens
Trigger: Thrown at line 12 when params.min === undefined && params.max === undefined — i.e. the rule was registered (data-val-range attributes) without either a min or max value.
Common situations: A [Range] attribute whose data-val-range-min / data-val-range-max attributes were both stripped or never emitted; a hand-built input with data-val-range but no bounds; sanitizer removing data-* attributes; tag helper misconfiguration.
Related errors
- EqualTo validator requires a non-empty "other" parameter.
- FileExtensions validator requires a non-empty "extensions"…
- length/minlength/maxlength validator requires at least one…
- regex validator requires a non-empty "pattern" parameter.
- assembly must be defined when using a descriptor.
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/ad4b4aa241280e1b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Components/Web.JS/src/Validation/Validators/Range.ts:12
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
import { ValidationContext, ValidationResult, Validator, pass, fail } from '../ValidationTypes';
// Validates that a numeric value falls within min/max bounds (inclusive).
// Non-numeric values fail. Uses Number() for parsing.
// Throws if neither bound is defined (rule has no effect).
export const rangeValidator: Validator = (context: ValidationContext): ValidationResult => {
const { value, params } = context;
if (params.min === undefined && params.max === undefined) {
throw new Error('Range validator requires at least one of "min" or "max" parameters.');
}
if (!value) {
return pass();
}
const num = Number(value);
if (isNaN(num)) {
return fail();
}
if (params.min !== undefined) {
if (num < Number(params.min)) {
return fail();
}
}
if (params.max !== undefined) {View on GitHub (pinned to 3600ca084e)