You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+75-1Lines changed: 75 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,11 +46,85 @@ var errors = result.Errors;
46
46
<sup><ahref='/Examples/BasicExample.cs#L12-L22'title='Snippet source file'>snippet source</a> | <ahref='#snippet-BasicExample'title='Start of snippet'>anchor</a></sup>
47
47
<!-- endSnippet -->
48
48
49
+
# Validators
50
+
51
+
There are several built-in validators available out-of-the-box. You can also provide your own validation logic via the [predicate validator](#predicate-validator) (aka `Must`).
52
+
53
+
## NotEmpty Validator
54
+
55
+
Ensures the value is not `null` for reference types or a default value for value types. For strings, ensures it is not `null`, an empty string, or only whitespace.
56
+
57
+
<!-- snippet: NotEmptyBasicExample -->
58
+
<aid='snippet-NotEmptyBasicExample'></a>
59
+
```cs
60
+
RuleFor(input)
61
+
.NotEmpty()
62
+
.Result();
63
+
```
64
+
<sup><ahref='/Examples/NotEmptyBasicExample.cs#L12-L16'title='Snippet source file'>snippet source</a> | <ahref='#snippet-NotEmptyBasicExample'title='Start of snippet'>anchor</a></sup>
65
+
<!-- endSnippet -->
66
+
67
+
## BetweenInclusive Validator
68
+
69
+
Ensures a number of any type (`int`, `float`, `double`, etc.) is greater than a minimum and less than a maximum.
70
+
71
+
<!-- snippet: BetweenInclusiveBasicExample -->
72
+
<aid='snippet-BetweenInclusiveBasicExample'></a>
73
+
```cs
74
+
RuleFor(input)
75
+
.BetweenInclusive(6, 14)
76
+
.Result();
77
+
```
78
+
<sup><ahref='/Examples/BetweenInclusiveBasicExample.cs#L12-L16'title='Snippet source file'>snippet source</a> | <ahref='#snippet-BetweenInclusiveBasicExample'title='Start of snippet'>anchor</a></sup>
79
+
<!-- endSnippet -->
80
+
81
+
## BetweenExclusive Validator
82
+
83
+
Ensures a number of any type (`int`, `float`, `double`, etc.) is greater than or equal to a minimum and less than or equal to a maximum.
84
+
85
+
<!-- snippet: BetweenExclusiveBasicExample -->
86
+
<aid='snippet-BetweenExclusiveBasicExample'></a>
87
+
```cs
88
+
RuleFor(input)
89
+
.BetweenExclusive(6, 14)
90
+
.Result();
91
+
```
92
+
<sup><ahref='/Examples/BetweenExclusiveBasicExample.cs#L12-L16'title='Snippet source file'>snippet source</a> | <ahref='#snippet-BetweenExclusiveBasicExample'title='Start of snippet'>anchor</a></sup>
93
+
<!-- endSnippet -->
94
+
95
+
## Equal Validator
96
+
97
+
Ensures the input is considered equal to the provided value. For reference types it checks if the two references are to the same instance (reference equality). For value types, it checks it the types and values are the same (value equality).
98
+
99
+
<!-- snippet: EqualBasicExample -->
100
+
<aid='snippet-EqualBasicExample'></a>
101
+
```cs
102
+
RuleFor(input)
103
+
.Equal(8)
104
+
.Result();
105
+
```
106
+
<sup><ahref='/Examples/EqualBasicExample.cs#L12-L16'title='Snippet source file'>snippet source</a> | <ahref='#snippet-EqualBasicExample'title='Start of snippet'>anchor</a></sup>
107
+
<!-- endSnippet -->
108
+
109
+
## Predicate Validator
110
+
111
+
The predicate (aka `Must`) validator allows you to provide your own validation logic by providing a delegate.
112
+
113
+
<!-- snippet: MustBasicExample -->
114
+
<aid='snippet-MustBasicExample'></a>
115
+
```cs
116
+
RuleFor(input)
117
+
.Must(input=>input==7)
118
+
.Result();
119
+
```
120
+
<sup><ahref='/Examples/MustBasicExample.cs#L12-L16'title='Snippet source file'>snippet source</a> | <ahref='#snippet-MustBasicExample'title='Start of snippet'>anchor</a></sup>
121
+
<!-- endSnippet -->
122
+
49
123
# Integrations
50
124
51
125
## Vogen
52
126
53
-
Extensions to integrate with Vogen validation methods.
127
+
Extensions to integrate with [Vogen](https://github.com/SteveDunn/Vogen) validation methods.
54
128
55
129
To get started, install the Vogen extensions nuget package, `CodingFlow.FluentValidation.VogenExtensions`.
Copy file name to clipboardExpand all lines: README.source.md
+35-1Lines changed: 35 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,11 +19,45 @@ Then you can add validation like this:
19
19
20
20
snippet: BasicExample
21
21
22
+
# Validators
23
+
24
+
There are several built-in validators available out-of-the-box. You can also provide your own validation logic via the [predicate validator](#predicate-validator) (aka `Must`).
25
+
26
+
## NotEmpty Validator
27
+
28
+
Ensures the value is not `null` for reference types or a default value for value types. For strings, ensures it is not `null`, an empty string, or only whitespace.
29
+
30
+
snippet: NotEmptyBasicExample
31
+
32
+
## BetweenInclusive Validator
33
+
34
+
Ensures a number of any type (`int`, `float`, `double`, etc.) is greater than a minimum and less than a maximum.
35
+
36
+
snippet: BetweenInclusiveBasicExample
37
+
38
+
## BetweenExclusive Validator
39
+
40
+
Ensures a number of any type (`int`, `float`, `double`, etc.) is greater than or equal to a minimum and less than or equal to a maximum.
41
+
42
+
snippet: BetweenExclusiveBasicExample
43
+
44
+
## Equal Validator
45
+
46
+
Ensures the input is considered equal to the provided value. For reference types it checks if the two references are to the same instance (reference equality). For value types, it checks it the types and values are the same (value equality).
47
+
48
+
snippet: EqualBasicExample
49
+
50
+
## Predicate Validator
51
+
52
+
The predicate (aka `Must`) validator allows you to provide your own validation logic by providing a delegate.
53
+
54
+
snippet: MustBasicExample
55
+
22
56
# Integrations
23
57
24
58
## Vogen
25
59
26
-
Extensions to integrate with Vogen validation methods.
60
+
Extensions to integrate with [Vogen](https://github.com/SteveDunn/Vogen) validation methods.
27
61
28
62
To get started, install the Vogen extensions nuget package, `CodingFlow.FluentValidation.VogenExtensions`.
0 commit comments