{"record":{"id":"ad4b4aa241280e1b","repo":"dotnet/aspnetcore","slug":"range-validator-requires-at-least-one-of-min-or","errorCode":null,"errorMessage":"Range validator requires at least one of \"min\" or \"max\" parameters.","messagePattern":"Range validator requires at least one of \"min\" or \"max\" parameters\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/Components/Web.JS/src/Validation/Validators/Range.ts","lineNumber":12,"sourceCode":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n\nimport { ValidationContext, ValidationResult, Validator, pass, fail } from '../ValidationTypes';\n\n// Validates that a numeric value falls within min/max bounds (inclusive).\n// Non-numeric values fail. Uses Number() for parsing.\n// Throws if neither bound is defined (rule has no effect).\nexport const rangeValidator: Validator = (context: ValidationContext): ValidationResult => {\n  const { value, params } = context;\n  if (params.min === undefined && params.max === undefined) {\n    throw new Error('Range validator requires at least one of \"min\" or \"max\" parameters.');\n  }\n\n  if (!value) {\n    return pass();\n  }\n\n  const num = Number(value);\n  if (isNaN(num)) {\n    return fail();\n  }\n\n  if (params.min !== undefined) {\n    if (num < Number(params.min)) {\n      return fail();\n    }\n  }\n\n  if (params.max !== undefined) {","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Web.JS/src/Validation/Validators/Range.ts#L1-L30","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"<!-- before -->\n<input name=\"Age\" data-val=\"true\" data-val-range=\"Out of range\" />\n<!-- after -->\n<input name=\"Age\" data-val=\"true\" data-val-range=\"Out of range\" data-val-range-min=\"18\" data-val-range-max=\"120\" />","handlingStrategy":"validation","validationCode":"function rangeConfigured(params: any): boolean {\n  return !!params && (params.min !== undefined || params.max !== undefined);\n}","typeGuard":"function hasRangeBound(p: unknown): boolean {\n  return !!p && ((p as any).min !== undefined || (p as any).max !== undefined);\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["blazor","validation","range","form-validation","misconfiguration"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}