dotnet/aspnetcore · error
length/minlength/maxlength validator requires at least one o
Error message
length/minlength/maxlength validator requires at least one of "min" or "max" parameters.
What it means
Thrown by the stringLength validator (StringLength.ts:12) when both params.min and params.max are undefined. This single validator backs three attributes — [StringLength], [MinLength], and [MaxLength] — all of which enforce string length bounds. With neither bound supplied the rule has no effect, so it throws to surface the misconfiguration rather than silently passing.
Source
Thrown at src/Components/Web.JS/src/Validation/Validators/StringLength.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 string length against min and/or max bounds (inclusive).
// Used for 'length' ([StringLength]), 'minlength' ([MinLength]), and 'maxlength' ([MaxLength]) rules.
// Throws if neither bound is defined (rule has no effect).
export const stringLengthValidator: Validator = (context: ValidationContext): ValidationResult => {
const { value, params } = context;
if (params.min === undefined && params.max === undefined) {
throw new Error('length/minlength/maxlength validator requires at least one of "min" or "max" parameters.');
}
if (!value) {
return pass();
}
if (params.min !== undefined) {
const min = parseInt(params.min, 10);
if (value.length < min) {
return fail();
}
}
if (params.max !== undefined) {
const max = parseInt(params.max, 10);
if (value.length > max) {
return fail();
}View on GitHub (pinned to 294cab2f9b)
Solutions
- Apply [StringLength(50, MinimumLength=3)] or [MinLength(3)] / [MaxLength(50)] and confirm the rendered input carries data-val-length-min and/or data-val-length-max with non-empty values.
- When wiring manually, pass params: { min: '3', max: '50' } — at least one must be present.
- Confirm bound values (including 0) are serialized as strings and not dropped by a serializer that treats 0 as falsy.
- Check that no tag helper or partial view is omitting the data-val-length-* attributes.
Example fix
// before <input name="Username" data-val-length /> // after <input name="Username" data-val-length data-val-length-min="3" data-val-length-max="50" />
Defensive patterns
Strategy: validation
Validate before calling
function hasLengthBound(params: Record<string, unknown>): boolean {
return params && (params.min !== undefined || params.max !== undefined);
} Type guard
function isStringLengthConfigured(p: any): p is { min?: string; max?: string } {
return p && (p.min !== undefined || p.max !== undefined);
} Prevention
- Always provide at least one bound on [StringLength]/[MinLength]/[MaxLength].
- Confirm data-val-length-min/max render on the input.
- Serialize bounds (including 0) as strings.
- Use the same validator name conventions the framework emits.
When it happens
Trigger: Invoking stringLengthValidator with a params object containing neither 'min' nor 'max'. The validator is registered under the 'length', 'minlength', and 'maxlength' rule names; if the corresponding data-val-* attribute fails to emit its bound(s), the JS validator throws.
Common situations: Model has [StringLength] / [MinLength] / [MaxLength] but the rendered input is missing both data-val-length-min and data-val-length-max (or the minlength/maxlength equivalents). Manual validator wiring that forgets bounds. Custom form rendering that strips data-val-length-* attributes.
Related errors
- EqualTo validator requires a non-empty "other" parameter.
- FileExtensions validator requires a non-empty "extensions" p
- Range validator requires at least one of "min" or "max" para
- regex validator requires a non-empty "pattern" parameter.
- Unknown passkey operation '${this.attrs.operation}'.
AI-assisted analysis of dotnet/aspnetcore@294cab2f9b (2026-08-06).
Data as JSON: /api/errors/4fb6a8b4b31755a8.
Report an issue: GitHub.