Skip to content

Commit 053290c

Browse files
committed
add custom() example using source param
fix freewilGH-2
1 parent ce119f7 commit 053290c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,29 @@ Use "%s" in the message to have the field name or label printed in the message:
315315
throw new Error("%s must be 'admin'.");
316316
}
317317
});
318+
319+
Validator based value on another field of the incoming source being validated
320+
321+
field("sport", "favorite sport").custom(function(value, source) {
322+
if (!source.country) {
323+
throw new error('unable to validate %s');
324+
}
325+
326+
switch (source.country) {
327+
case 'US':
328+
if (value !=== 'baseball') {
329+
throw new Error('America likes baseball');
330+
}
331+
break;
332+
333+
case 'UK':
334+
if (value !=== 'football') {
335+
throw new Error('UK likes football');
336+
}
337+
break;
338+
}
339+
340+
});
318341

319342

320343
### http.ServerRequest.prototype.form

0 commit comments

Comments
 (0)