wshaddix/dotnet-skills/validation-patterns
Claude Code and agent skill by wshaddix/dotnet-skills
- community
Checking that the SKILL.md file is still in the repository.
Comprehensive validation patterns for ASP.NET Core applications. Covers FluentValidation integration, DataAnnotations, IValidatableObject, IValidateOptions<T>, MediatR pipeline behavior, and client-side validation. Use when implementing validation in ASP.NET Core applications, setting up FluentValidation, creating custom validators, configuring options validation, or implementing cross-field validation.
Install
npx vskill@latest install wshaddix/dotnet-skills/validation-patternsSKILL.md
Validation Patterns in ASP.NET Core
Rationale
Validation is critical for both security and user experience. Poor validation leads to invalid data, security vulnerabilities, and confusing error messages. These patterns provide a comprehensive approach to validation at multiple layers.
Validation Strategy
| Layer | Purpose | Technology | |
|---|---|---|---|
| Client-Side | Immediate feedback, reduce server load | jQuery Validation, HTML5 | |
| Model Binding | Data type/format validation | Model Binders | |
| Application | Business rule validation | FluentValidation, DataAnnotations | |
| Configuration | Startup validation | IValidateOptions<T> | |
| Database | Constraint enforcement | EF Core Configurations |
Validation Approach Decision Tree
Choose the validation approach based on complexity:
- DataAnnotations (default) -- declarative
[Required],[Range],[StringLength],[RegularExpression]attributes. Best for simple property-level constraints. - `IValidatableObject` -- implement
Validate()for cross-property rules. Best for date range comparisons, conditional required fields. - Custom `ValidationAttribute` -- subclass
ValidationAttributefor reusable property-level rules. - `IValidateOptions<T>` -- validate configuration/options classes at startup with access to DI services.
- FluentValidation -- third-party library for complex, testable validation with fluent API. Best for async validators, database-dependent rules.
Pattern 1: DataAnnotations
The System.ComponentModel.DataAnnotations namespace provides declarative validation through attributes.
Attribute Reference
| Attribute | Purpose | Example | |
|---|---|---|---|
[Required] | Non-null, non-empty | [Required] | |
[StringLength] | Min/max length | [StringLength(200, MinimumLength = 1)] | |
[Range] | Numeric/date range | [Range(1, 100)] | |
[RegularExpression] | Pattern match | [RegularExpression(@"^\d{5}$")] | |
[EmailAddress] | Email format | [EmailAddress] | |
[Phone] | Phone format | [Phone] | |
[Url] | URL format | [Url] | |
[CreditCard] | Luhn check | [CreditCard] | |
[Compare] | Property equality | [Compare(nameof(Password))] | |
[MaxLength] / [MinLength] | Collection/string length | [MaxLength(50)] | |
[AllowedValues] (.NET 8+) | Value allowlist | [AllowedValues("Draft", "Published")] | |
[DeniedValues] (.NET 8+) | Value denylist | [DeniedValues("Admin", "Root")] | |
[Length] (.NET 8+) | Min and max in one | [Length(1, 200)] | |
[Base64String] (.NET 8+) | Base64 format | [Base64String] |
Pattern 2: Custom ValidationAttribute
Create reusable validation attributes for domain-specific rules.
Property-Level
Class-Level
Pattern 3: IValidatableObject
Implement IValidatableObject for cross-property validation within the model:
When to use `IValidatableObject` vs custom attribute: Use IValidatableObject when validation logic is specific to one model. Use custom ValidationAttribute when the same rule applies across multiple models.
Pattern 4: IValidateOptions<T>
Validate configuration/options classes at startup with access to DI services:
Registration
Pattern 5: FluentValidation Setup
NuGet Packages
Configuration
Basic Validator
Conditional Validation
Collection Validation
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/validation-patterns/SKILL.md
Popularity
- Repository stars
- 35
- Repository forks
- 3
- 7-day trend score
- 18
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 18 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/wshaddix/dotnet-skills/validation-patterns)