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
+24-24Lines changed: 24 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,56 +54,56 @@ There are several built-in validators available out-of-the-box. You can also pro
54
54
55
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
56
57
-
<!-- snippet: NotEmptyBasicExample-->
58
-
<aid='snippet-NotEmptyBasicExample'></a>
57
+
<!-- snippet: NotEmptyExample-->
58
+
<aid='snippet-NotEmptyExample'></a>
59
59
```cs
60
60
RuleFor(input)
61
61
.NotEmpty()
62
62
.Result();
63
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>
64
+
<sup><ahref='/Examples/NotEmptyExample.cs#L12-L16'title='Snippet source file'>snippet source</a> | <ahref='#snippet-NotEmptyExample'title='Start of snippet'>anchor</a></sup>
65
65
<!-- endSnippet -->
66
66
67
67
## BetweenInclusive Validator
68
68
69
69
Ensures a number of any type (`int`, `float`, `double`, etc.) is greater than a minimum and less than a maximum.
70
70
71
-
<!-- snippet: BetweenInclusiveBasicExample-->
72
-
<aid='snippet-BetweenInclusiveBasicExample'></a>
71
+
<!-- snippet: BetweenInclusiveExample-->
72
+
<aid='snippet-BetweenInclusiveExample'></a>
73
73
```cs
74
74
RuleFor(input)
75
75
.BetweenInclusive(6, 14)
76
76
.Result();
77
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>
78
+
<sup><ahref='/Examples/BetweenInclusiveExample.cs#L12-L16'title='Snippet source file'>snippet source</a> | <ahref='#snippet-BetweenInclusiveExample'title='Start of snippet'>anchor</a></sup>
79
79
<!-- endSnippet -->
80
80
81
81
## BetweenExclusive Validator
82
82
83
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
84
85
-
<!-- snippet: BetweenExclusiveBasicExample-->
86
-
<aid='snippet-BetweenExclusiveBasicExample'></a>
85
+
<!-- snippet: BetweenExclusiveExample-->
86
+
<aid='snippet-BetweenExclusiveExample'></a>
87
87
```cs
88
88
RuleFor(input)
89
89
.BetweenExclusive(6, 14)
90
90
.Result();
91
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>
92
+
<sup><ahref='/Examples/BetweenExclusiveExample.cs#L12-L16'title='Snippet source file'>snippet source</a> | <ahref='#snippet-BetweenExclusiveExample'title='Start of snippet'>anchor</a></sup>
93
93
<!-- endSnippet -->
94
94
95
95
## Equal Validator
96
96
97
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
98
99
-
<!-- snippet: EqualBasicExample-->
100
-
<aid='snippet-EqualBasicExample'></a>
99
+
<!-- snippet: EqualExample-->
100
+
<aid='snippet-EqualExample'></a>
101
101
```cs
102
102
RuleFor(input)
103
103
.Equal(8)
104
104
.Result();
105
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>
106
+
<sup><ahref='/Examples/EqualExample.cs#L12-L16'title='Snippet source file'>snippet source</a> | <ahref='#snippet-EqualExample'title='Start of snippet'>anchor</a></sup>
107
107
<!-- endSnippet -->
108
108
109
109
## MinimumLength Validator
@@ -124,42 +124,42 @@ RuleFor(input)
124
124
125
125
Aka `Matches`, ensure the string passes a regular expression test.
126
126
127
-
<!-- snippet: MatchesBasicExample-->
128
-
<aid='snippet-MatchesBasicExample'></a>
127
+
<!-- snippet: MatchesExample-->
128
+
<aid='snippet-MatchesExample'></a>
129
129
```cs
130
130
RuleFor(input)
131
131
.Matches("cat")
132
132
.Result();
133
133
```
134
-
<sup><ahref='/Examples/MatchesExample.cs#L12-L16'title='Snippet source file'>snippet source</a> | <ahref='#snippet-MatchesBasicExample'title='Start of snippet'>anchor</a></sup>
134
+
<sup><ahref='/Examples/MatchesExample.cs#L12-L16'title='Snippet source file'>snippet source</a> | <ahref='#snippet-MatchesExample'title='Start of snippet'>anchor</a></sup>
135
135
<!-- endSnippet -->
136
136
137
137
## Predicate Validator
138
138
139
139
The predicate (aka `Must`) validator allows you to provide your own validation logic by providing a delegate.
140
140
141
-
<!-- snippet: MustBasicExample-->
142
-
<aid='snippet-MustBasicExample'></a>
141
+
<!-- snippet: MustExample-->
142
+
<aid='snippet-MustExample'></a>
143
143
```cs
144
144
RuleFor(input)
145
145
.Must(input=>input==7)
146
146
.Result();
147
147
```
148
-
<sup><ahref='/Examples/MustBasicExample.cs#L12-L16'title='Snippet source file'>snippet source</a> | <ahref='#snippet-MustBasicExample'title='Start of snippet'>anchor</a></sup>
148
+
<sup><ahref='/Examples/MustExample.cs#L12-L16'title='Snippet source file'>snippet source</a> | <ahref='#snippet-MustExample'title='Start of snippet'>anchor</a></sup>
149
149
<!-- endSnippet -->
150
150
151
151
## IsGuid Validator
152
152
153
153
Ensures the string can be parsed into a valid GUID.
154
154
155
-
<!-- snippet: IsGuidBasicExample-->
156
-
<aid='snippet-IsGuidBasicExample'></a>
155
+
<!-- snippet: IsGuidExample-->
156
+
<aid='snippet-IsGuidExample'></a>
157
157
```cs
158
158
RuleFor(input)
159
159
.IsGuid()
160
160
.Result();
161
161
```
162
-
<sup><ahref='/Examples/IsGuidBasicExample.cs#L12-L16'title='Snippet source file'>snippet source</a> | <ahref='#snippet-IsGuidBasicExample'title='Start of snippet'>anchor</a></sup>
162
+
<sup><ahref='/Examples/IsGuidExample.cs#L12-L16'title='Snippet source file'>snippet source</a> | <ahref='#snippet-IsGuidExample'title='Start of snippet'>anchor</a></sup>
163
163
<!-- endSnippet -->
164
164
165
165
# Customizing
@@ -168,14 +168,14 @@ RuleFor(input)
168
168
169
169
The `WithMessage` method can be used to change the validation error message for a validator.
170
170
171
-
<!-- snippet: WithMessageBasicExample-->
172
-
<aid='snippet-WithMessageBasicExample'></a>
171
+
<!-- snippet: WithMessageExample-->
172
+
<aid='snippet-WithMessageExample'></a>
173
173
```cs
174
174
RuleFor(input)
175
175
.Equal(8).WithMessage("The two numbers are not equal.")
176
176
.Result();
177
177
```
178
-
<sup><ahref='/Examples/WithMessageBasicExample.cs#L13-L17'title='Snippet source file'>snippet source</a> | <ahref='#snippet-WithMessageBasicExample'title='Start of snippet'>anchor</a></sup>
178
+
<sup><ahref='/Examples/WithMessageExample.cs#L13-L17'title='Snippet source file'>snippet source</a> | <ahref='#snippet-WithMessageExample'title='Start of snippet'>anchor</a></sup>
0 commit comments