@@ -123,11 +123,11 @@ Expects a date with default format `YYYY-MM-DD`
123123specify date format, supported
124124```
125125YYYY-MM-DD
126- DD-MM-YYYY'
127- MM-DD-YYYY'
128- YYYY/MM/DD'
129- DD/MM/YYYY'
130- MM/DD/YYYY'
126+ DD-MM-YYYY
127+ MM-DD-YYYY
128+ YYYY/MM/DD
129+ DD/MM/YYYY
130+ MM/DD/YYYY
131131```
132132##### minimumNumber(min)
133133* ` min ` * Mandatory* Number
@@ -151,13 +151,26 @@ Expects number/string and must not be one of given array `excludes`
151151* ` countryCode ` * Mandatory* String
152152Expects mobile number with or without ` countryCode `
153153##### isMobileNumberWithCountryCodeMandatory()
154- Expects mobile number which should starts with country code set at ` isMobileNumberWithCountryCode `
154+ Expects mobile number which should starts with the country code set with ` isMobileNumberWithCountryCode `
155155##### isMobileNumberWithMinimumLength(min)
156156* ` min ` * Mandatory* Number
157157Minimum length of mobile number without country code
158158##### isMobileNumberWithMaximumLength(max)
159159* ` max ` * Mandatory* Number
160160Maximum length of mobile number without country code
161+ ##### customValidator(function)
162+ * ` function ` * Mandatory* Function
163+ A function with arguments (` value ` , ` req ` , ` error ` )
164+ ` value ` is the value of the field
165+ ` req ` request object
166+ ` error ` function with takes error message, should be called on error
167+ ``` js
168+ (value , req , error ) => {
169+ if (value !== 100 ) {
170+ error (' Invalid value customValidator' );
171+ }
172+ }
173+ ```
161174##### addChild(child)
162175* ` child ` * Mandatory* field definition object
163176Add a child object for arrays and objects
@@ -292,6 +305,13 @@ Error object
292305```
293306##### addParams(paramList)
294307* ` paramList ` * Mandatory* Array of field definition objects
308+ ``` js
309+ validateBody ().addParams ([
310+ // Add List of definition here
311+ param (' field1' ).isRequired ().end (),
312+ ]).done ()
313+ ```
314+ Definintion of a field here : [ Defining a Field] ( #defining-a-field )
295315##### done() :bangbang ::bangbang : Mandatory
296316Ends a validation definition
297317## Dealing with nested objects
@@ -317,7 +337,7 @@ Should send http status code 500 in case of error
317337``` js
318338router .post (' /users/:id' ,
319339validateBody ().isToBeRejected ().sendErrorCode (500 ).addParams ([
320- param (' field1' ).isRequired ().end (),
340+ param (' field1' ).isRequired ().end (), // Use end() to end a definition
321341 param (' field2' ).isRequired ().isArray ().isRequired ().addChild (
322342 param (' field2-array' ).isObject ().addChild ( // field2-array is for tracking, you can give any name here
323343 param (' field21' ).isNumber ().isRequired ().end ()
@@ -330,7 +350,12 @@ validateBody().isToBeRejected().sendErrorCode(500).addParams([
330350 param (' field4' ).isRequired ().isArray ().isRequired ().addChild (
331351 param (' field4-array' ).isNumber ().end ()
332352 ).end (),
333- ]).done (),
353+ ]).done (), // Use done() to end a validation
354+ validateParam ().isToBeRejected ().sendErrorCode (500 ).addParams ([
355+ param (' field1' ).isRequired ().end (), // Use end() to end a definition
356+ ]).done (), // Use done() to end a validation
357+ // define validateQuery(),
358+ // define validateHeader(),
334359(req , res , next ) => {
335360
336361 // Main Service Here
0 commit comments