WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ Allows you to add custom rules by giving a callback function and a custom class.

#### Arguments

- `callback` (required) - the callback function.
- `customClass` (required) - the name of the class.
- `callback` (required) - the callback function, that must return `true` if the value is valid.
- `customClass` (required) - the name of the class, which must match the pattern `/^[a-zA-Z\d]+$/`.

### CaZipCode

Expand Down Expand Up @@ -331,7 +331,9 @@ The following is an example for the extra IP assert:

```js
const Validator = require('validator.js').Validator;
const is = require('validator.js').Assert.extend(require('validator.js-asserts'));
const is = require('validator.js').Assert.extend(
require('validator.js-asserts')
);
const validator = new Validator();

// Validate IP `1.3.3.7`.
Expand Down
13 changes: 12 additions & 1 deletion src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,18 @@ export interface ValidatorJSAsserts {
/** Valid Canadian ZIP code (postal code). */
caZipCode(): AssertInstance;

/** Run a custom callback function, passing a custom class name. */
/**
* Run a custom callback function, passing a custom class name.
* @param fn - Callback function that receives the value to validate, which should return `true` if valid.
* @param customClass - Custom class name to use for the assert. Must match the pattern `/^[a-zA-Z\d]+$/`.
* @example
* ```js
* is.callback(
* (value) => typeof value === 'string' && value.length > 0,
* 'NonEmptyString'
* );
* ```
*/
callback(fn: (value: unknown) => boolean, customClass: string): AssertInstance;

/** Valid Brazilian CPF number. @requires cpf */
Expand Down