react-hook-form-rules 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -43
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
# React-hook-form-rules
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This is a small library that contains a few rules for clearer validation handling in the [react-hook-form](https://www.react-hook-form.com/) library.
|
|
4
|
+
|
|
5
|
+
### Contacts
|
|
6
|
+
|
|
7
|
+
Hello everyone 👋.
|
|
8
|
+
|
|
9
|
+
If you have any questions or suggestions, [my github profile](https://github.com/chopperqt).
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Rules
|
|
14
|
+
|
|
15
|
+
### getRequiredRule
|
|
16
|
+
|
|
17
|
+
#### Description
|
|
4
18
|
This rule makes the field required.
|
|
5
19
|
|
|
6
|
-
|
|
20
|
+
#### Options
|
|
7
21
|
| Option | Type | Default | Description |
|
|
8
22
|
| -------- | --------- | ------ | ---------- |
|
|
9
23
|
| isRequired | boolean | true | |
|
|
10
24
|
| message | string | "This field is required." | . |
|
|
11
25
|
|
|
12
|
-
|
|
26
|
+
#### Code example
|
|
13
27
|
```
|
|
14
28
|
import { getRequiredRule } from 'react-hook-form-rules';
|
|
15
29
|
|
|
@@ -25,20 +39,20 @@ const {...} = useController({
|
|
|
25
39
|
|
|
26
40
|
|
|
27
41
|
|
|
28
|
-
|
|
42
|
+
### getRequiredArrayRule
|
|
29
43
|
|
|
30
|
-
|
|
44
|
+
#### Description
|
|
31
45
|
This rule makes the array field required.
|
|
32
46
|
|
|
33
47
|
|
|
34
|
-
|
|
48
|
+
#### Options
|
|
35
49
|
| Option | Type | Default | Description |
|
|
36
50
|
| -------- | --------- | ------ | ---------- |
|
|
37
51
|
| arr | array | [] | |
|
|
38
52
|
| message | string | "This field is required." | |
|
|
39
53
|
|
|
40
54
|
|
|
41
|
-
|
|
55
|
+
#### Code example
|
|
42
56
|
```
|
|
43
57
|
import { getRequiredArrayRule } from 'react-hook-form-rules';
|
|
44
58
|
|
|
@@ -53,20 +67,20 @@ const {...} = useController({
|
|
|
53
67
|
|
|
54
68
|
|
|
55
69
|
|
|
56
|
-
|
|
70
|
+
### getRequiredObjectRule
|
|
57
71
|
|
|
58
|
-
|
|
72
|
+
#### Description
|
|
59
73
|
This rule makes the object field required.
|
|
60
74
|
|
|
61
75
|
|
|
62
|
-
|
|
76
|
+
#### Options
|
|
63
77
|
| Option | Type | Default | Description |
|
|
64
78
|
| -------- | --------- | ------ | ---------- |
|
|
65
79
|
| obj | object | {} | |
|
|
66
80
|
| message | string | "This field is required." | |
|
|
67
81
|
|
|
68
82
|
|
|
69
|
-
|
|
83
|
+
#### Code example
|
|
70
84
|
```
|
|
71
85
|
import { getRequiredObjectRule } from 'react-hook-form-rules';
|
|
72
86
|
|
|
@@ -80,18 +94,18 @@ const {...} = useController({
|
|
|
80
94
|
|
|
81
95
|
|
|
82
96
|
|
|
83
|
-
|
|
97
|
+
### getMaxRule
|
|
84
98
|
|
|
85
|
-
|
|
99
|
+
#### Description
|
|
86
100
|
This rule returns an error if the number is greater than the specified value.
|
|
87
101
|
|
|
88
|
-
|
|
102
|
+
#### Options
|
|
89
103
|
| Option | Type | Default | Description |
|
|
90
104
|
| -------- | --------- | ------ | ---------- |
|
|
91
105
|
| max | number | - | - |
|
|
92
106
|
| message | string | - | - |
|
|
93
107
|
|
|
94
|
-
|
|
108
|
+
#### Code example
|
|
95
109
|
```
|
|
96
110
|
import { getMaxRule } from 'react-hook-form-rules';
|
|
97
111
|
|
|
@@ -105,12 +119,12 @@ const {...} = useController({
|
|
|
105
119
|
|
|
106
120
|
|
|
107
121
|
|
|
108
|
-
|
|
122
|
+
### getMaxLengthRule
|
|
109
123
|
|
|
110
|
-
|
|
124
|
+
#### Description
|
|
111
125
|
This rule checks that the number of characters in the string does not exceed the specified value.
|
|
112
126
|
|
|
113
|
-
|
|
127
|
+
#### Options
|
|
114
128
|
| Option | Type | Default | Description |
|
|
115
129
|
| -------- | --------- | ------ | ---------- |
|
|
116
130
|
| maxLength | number | - | - |
|
|
@@ -131,19 +145,19 @@ const {...} = useController({
|
|
|
131
145
|
|
|
132
146
|
|
|
133
147
|
|
|
134
|
-
|
|
148
|
+
### getMaxArrayLengthRule
|
|
135
149
|
|
|
136
|
-
|
|
150
|
+
#### Description
|
|
137
151
|
This rule returns an error if the number of values in the array exceeds the specified limit.
|
|
138
152
|
|
|
139
|
-
|
|
153
|
+
#### Options
|
|
140
154
|
| Option | Type | Default | Description |
|
|
141
155
|
| -------- | --------- | ------ | ---------- |
|
|
142
156
|
| arr | arrray | - | - |
|
|
143
157
|
| maxLength | number | - | - |
|
|
144
158
|
| message | string | - | - |
|
|
145
159
|
|
|
146
|
-
|
|
160
|
+
#### Code example
|
|
147
161
|
```
|
|
148
162
|
import { getMaxArrayLengthRule } from 'react-hook-form-rules';
|
|
149
163
|
|
|
@@ -156,18 +170,18 @@ const {...} = useController({
|
|
|
156
170
|
|
|
157
171
|
|
|
158
172
|
|
|
159
|
-
|
|
173
|
+
### getMinRule
|
|
160
174
|
|
|
161
|
-
|
|
175
|
+
#### Description
|
|
162
176
|
This rule checks that the string contains a minimum number of characters.
|
|
163
177
|
|
|
164
|
-
|
|
178
|
+
#### Options
|
|
165
179
|
| Option | Type | Default | Description |
|
|
166
180
|
| -------- | --------- | ------ | ---------- |
|
|
167
181
|
| min | number | - | - |
|
|
168
182
|
| message | string | - | - |
|
|
169
183
|
|
|
170
|
-
|
|
184
|
+
#### Code example
|
|
171
185
|
```
|
|
172
186
|
import { getMinRule } from 'react-hook-form-rules';
|
|
173
187
|
|
|
@@ -181,18 +195,18 @@ const {...} = useController({
|
|
|
181
195
|
|
|
182
196
|
|
|
183
197
|
|
|
184
|
-
|
|
198
|
+
### getMinLengthRule
|
|
185
199
|
|
|
186
|
-
|
|
200
|
+
#### Description
|
|
187
201
|
The rule checks that the string contains at least the specified number of characters.
|
|
188
202
|
|
|
189
|
-
|
|
203
|
+
#### Options
|
|
190
204
|
| Option | Type | Default | Description |
|
|
191
205
|
| -------- | --------- | ------ | ---------- |
|
|
192
206
|
| minLength | number | - | - |
|
|
193
207
|
| message | string | - | - |
|
|
194
208
|
|
|
195
|
-
|
|
209
|
+
#### Code example
|
|
196
210
|
```
|
|
197
211
|
import { getMinLengthRule } from 'react-hook-form-rules';
|
|
198
212
|
|
|
@@ -206,19 +220,19 @@ const {...} = useController({
|
|
|
206
220
|
|
|
207
221
|
|
|
208
222
|
|
|
209
|
-
|
|
223
|
+
### getMinArrayLengthRule
|
|
210
224
|
|
|
211
|
-
|
|
225
|
+
#### Description
|
|
212
226
|
The rule checks that the array contains a minimum number of elements.
|
|
213
227
|
|
|
214
|
-
|
|
228
|
+
#### Options
|
|
215
229
|
| Option | Type | Default | Description |
|
|
216
230
|
| -------- | --------- | ------ | ---------- |
|
|
217
231
|
| arr | arrray | - | - |
|
|
218
232
|
| minLength | number | - | - |
|
|
219
233
|
| message | string | - | - |
|
|
220
234
|
|
|
221
|
-
|
|
235
|
+
#### Code example
|
|
222
236
|
```
|
|
223
237
|
import { getMinArrayLengthRule } from 'react-hook-form-rules';
|
|
224
238
|
|
|
@@ -229,18 +243,18 @@ const {...} = useController({
|
|
|
229
243
|
})
|
|
230
244
|
```
|
|
231
245
|
|
|
232
|
-
|
|
246
|
+
### getEmailRule
|
|
233
247
|
|
|
234
|
-
|
|
248
|
+
#### Description
|
|
235
249
|
he rule checks the entered email for correctness.
|
|
236
250
|
|
|
237
|
-
|
|
251
|
+
#### Options
|
|
238
252
|
| Option | Type | Default | Description |
|
|
239
253
|
| -------- | --------- | ------ | ---------- |
|
|
240
254
|
| pattern | RegExp | - | - |
|
|
241
255
|
| message | string | - | - |
|
|
242
256
|
|
|
243
|
-
|
|
257
|
+
#### Code example
|
|
244
258
|
```
|
|
245
259
|
import { getEmailRule } from 'react-hook-form-rules';
|
|
246
260
|
|
|
@@ -254,18 +268,18 @@ const {...} = useController({
|
|
|
254
268
|
|
|
255
269
|
|
|
256
270
|
|
|
257
|
-
|
|
271
|
+
### getUrlRule
|
|
258
272
|
|
|
259
|
-
|
|
273
|
+
#### Description
|
|
260
274
|
The rule checks the entered URL for correctness.
|
|
261
275
|
|
|
262
|
-
|
|
276
|
+
#### Options
|
|
263
277
|
| Option | Type | Default | Description |
|
|
264
278
|
| -------- | --------- | ------ | ---------- |
|
|
265
279
|
| pattern | RegExp | - | - |
|
|
266
280
|
| message | string | - | - |
|
|
267
281
|
|
|
268
|
-
|
|
282
|
+
#### Code example
|
|
269
283
|
```
|
|
270
284
|
import { getUrlRule } from 'react-hook-form-rules';
|
|
271
285
|
|