dotnet/aspnetcore · error

Range validator requires at least one of "min" or "max" para

Error message

Range validator requires at least one of "min" or "max" parameters.

What it means

Thrown by the Range validator (Range.ts:12) when both params.min and params.max are undefined. Range enforces inclusive numeric bounds; with neither bound the rule is a no-op, so the validator throws to flag a rule that would silently validate everything. At least one bound must be supplied.

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 294cab2f9b)

Solutions

  1. Use [Range(1, 100)] (or [Range(typeof(decimal), "0", "10")]) on the property and confirm the rendered input has data-val-range-min and/or data-val-range-max.
  2. When wiring manually, pass params: { min: '1', max: '100' } (at least one required).
  3. Distinguish a real bound of 0 from a missing bound — ensure 0 is serialized as the string "0", not omitted.
  4. Verify data-val-range-* attributes survive any custom rendering/tag-helper pipeline.

Example fix

// before
<input name="Age" data-val-range />

// after
<input name="Age" data-val-range data-val-range-min="18" data-val-range-max="120" />
Defensive patterns

Strategy: validation

Validate before calling

function hasRangeBound(params: Record<string, unknown>): boolean {
  return params && (params.min !== undefined || params.max !== undefined);
}

Type guard

function isRangeConfigured(p: any): p is { min?: string; max?: string } {
  return p && (p.min !== undefined || p.max !== undefined);
}

Prevention

When it happens

Trigger: Invoking rangeValidator with a params object containing neither 'min' nor 'max'. Typically emitted from [Range(min,max)]; if both arguments are missing or the data-val-range-min/max metadata is absent, the JS validator throws.

Common situations: Model uses [Range] with no arguments (compile error in C# but possible via dynamic metadata), or a custom edit form drops both data-val-range-min and data-val-range-max. Manual validator registration that omits bounds. Serialization edge cases where 0 bounds are sent as missing.

Related errors


AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06). Data as JSON: /api/errors/ad4b4aa241280e1b. Report an issue: GitHub.