Skip to content
Merged
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ validator.isIP(str, version); // Checks if the string is an IP (version 4 or 6).
validator.isPort(str); // Check if the string is a valid port number.
validator.isISBN(str, version); // Checks if the string is an ISBN (version 10 or 13).
validator.isISIN(str); // Checks if the string is an ISIN (stock/security identifier).
validator.isISO8601(str); // Checks if the string is a valid ISO 8601 date.
validator.isISO8601(str, options); // Checks if the string is a valid ISO 8601 date. Use the option strict = true for additional checks for a valid date, e.g. invalidates dates like 2019-02-29.
validator.isJSON(str); // Checks if the string is valid JSON (note: uses JSON.parse).
validator.isJWT(str) // Checks if the string is valid JWT.
validator.isObject(object); // Checks if the object is valid Object (null, functions, arrays will return false)
Expand Down Expand Up @@ -927,12 +927,12 @@ validator.isInstance(value, target); // Checks value is an instance of the targe
| `@IsVariableWidth()` | Checks if the string contains a mixture of full and half-width chars. |
| `@IsHexColor()` | Checks if the string is a hexadecimal color. |
| `@IsHexadecimal()` | Checks if the string is a hexadecimal number. |
| `@IsMACAddress()` | Checks if the string is a MAC Address. |
| `@IsMACAddress()` | Checks if the string is a MAC Address. |
| `@IsIP(version?: "4"\|"6")` | Checks if the string is an IP (version 4 or 6). |
| `@IsPort()` | Check if the string is a valid port number. |
| `@IsISBN(version?: "10"\|"13")` | Checks if the string is an ISBN (version 10 or 13). |
| `@IsISIN()` | Checks if the string is an ISIN (stock/security identifier). |
| `@IsISO8601()` | Checks if the string is a valid ISO 8601 date. |
| `@IsISO8601(options?: IsISO8601Options)` | Checks if the string is a valid ISO 8601 date. Use the option strict = true for additional checks for a valid date, e.g. invalidates dates like 2019-02-29. |
| `@IsJSON()` | Checks if the string is valid JSON. |
| `@IsJWT()` | Checks if the string is valid JWT. |
| `@IsObject()` | Checks if the object is valid Object (null, functions, arrays will return false). |
Expand Down
9 changes: 5 additions & 4 deletions src/decorator/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ export function IsAlpha(locale?: string, validationOptions?: ValidationOptions)
type: ValidationTypes.IS_ALPHA,
target: object.constructor,
propertyName: propertyName,
constraints: [locale],
constraints: [locale],
validationOptions: validationOptions
};
getFromContainer(MetadataStorage).addValidationMetadata(new ValidationMetadata(args));
Expand All @@ -623,7 +623,7 @@ export function IsAlphanumeric(locale?: string, validationOptions?: ValidationOp
type: ValidationTypes.IS_ALPHANUMERIC,
target: object.constructor,
propertyName: propertyName,
constraints: [locale],
constraints: [locale],
validationOptions: validationOptions
};
getFromContainer(MetadataStorage).addValidationMetadata(new ValidationMetadata(args));
Expand Down Expand Up @@ -908,14 +908,15 @@ export function IsISIN(validationOptions?: ValidationOptions) {
}

/**
* Checks if the string is a valid ISO 8601 date.
* Checks if the string is a valid ISO 8601 date. Use the option strict = true for additional checks for a valid date, e.g. invalidates dates like 2019-02-29.
*/
export function IsISO8601(validationOptions?: ValidationOptions) {
export function IsISO8601(options?: ValidatorJS.IsISO8601Options, validationOptions?: ValidationOptions) {
return function (object: Object, propertyName: string) {
const args: ValidationMetadataArgs = {
type: ValidationTypes.IS_ISO8601,
target: object.constructor,
propertyName: propertyName,
constraints: [options],
validationOptions: validationOptions
};
getFromContainer(MetadataStorage).addValidationMetadata(new ValidationMetadata(args));
Expand Down
11 changes: 6 additions & 5 deletions src/validation/Validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class Validator {
case ValidationTypes.IS_ISIN:
return this.isISIN(value);
case ValidationTypes.IS_ISO8601:
return this.isISO8601(value);
return this.isISO8601(value, metadata.constraints[0]);
case ValidationTypes.IS_JSON:
return this.isJSON(value);
case ValidationTypes.IS_JWT:
Expand Down Expand Up @@ -274,7 +274,7 @@ export class Validator {
return this.isHash(value, metadata.constraints[0]);
case ValidationTypes.IS_ISSN:
return this.isISSN(value, metadata.constraints[0]);

/* array checkers */
case ValidationTypes.ARRAY_CONTAINS:
return this.arrayContains(value, metadata.constraints[0]);
Expand Down Expand Up @@ -444,7 +444,7 @@ export class Validator {
return false;
}
}

return Number.isFinite(value);
}

Expand Down Expand Up @@ -717,9 +717,10 @@ export class Validator {
/**
* Checks if the string is a valid ISO 8601 date.
* If given value is not a string, then it returns false.
* Use the option strict = true for additional checks for a valid date, e.g. invalidates dates like 2019-02-29.
*/
isISO8601(value: unknown): boolean {
return typeof value === "string" && this.validatorJs.isISO8601(value);
isISO8601(value: unknown, options?: ValidatorJS.IsISO8601Options): boolean {
return typeof value === "string" && this.validatorJs.isISO8601(value, options);
}

/**
Expand Down