Validating primitive types
See original GitHub issueI’m trying to find a way how I can use built-in validators to validate primitive types like strings or ints. For example, I would like to be able to use EmailValidator
to validate a string value (not a string property of a complex type) by calling something like Validate
. But EmailValidator
is IPropertyValidator
, not IValidator
.
Any ideas how to use FluentValidation to validate primitive types?
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
How to validate primitive types with FluentValidation in ...
The question is, how to gracefully validate primitive type arguments in ASP.net core using FluentValidation? For complex types, I have a ...
Read more >Validating primitive types · Issue #184 · FluentValidation ...
I'm trying to find a way how I can use built-in validators to validate primitive types like strings or ints. For example, I...
Read more >Recommended and Unrecommended Primitive Types
Our Platform includes a validation mechanism that identifies Unrecommended Primitive Types, which are more likely to cause issues in the ...
Read more >Data Validation — Overview, Types, How To Perform
Type validation often refers to checking whether or not an entry matches the field. For example, you might try entering text in the...
Read more >Data Validation - Overview, Types, Practical Examples
Types of Data Validation · 1. Data Type Check · 2. Code Check · 3. Range Check · 4. Format Check · 5....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sure, here’s an example that chains multiple rules on a string property, within an extension method.
This is actually how all of FV’s default validation rules (NotNull, NotEmpty etc) work- they’re all extesnions on IRuleBuilder that perform certain actions (usually calling SetValidator to encapsulate within a custom property validator)
Yes, you have a couple of options. You can use the approach I documented above, by creating an AbstractValidator instance that acts on strings. The other option is to write an extension that wraps the multiple calls to RuleFor.