Skip to content

Commit 7771cea

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into perf/package-optimisation
# Conflicts: # src/validation/ValidationExecutor.ts
2 parents 241b29d + 8bc5f96 commit 7771cea

15 files changed

Lines changed: 1429 additions & 977 deletions

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@
22

33
_This changelog follows the [keep a changelog][keep-a-changelog]_ format to maintain a human readable changelog.
44

5+
## [0.15.0](https://github.com/typestack/class-validator/compare/v0.14.4...v0.15.0) (2026-02-25)
6+
7+
### BREAKING CHANGES
8+
9+
- Added options argument to IsIBAN validator ([#2618](https://github.com/typestack/class-validator/pull/2618)), which breaks any existing usage of this decorator that pass an argument to the decorator, e.g. `@IsIBAN({forbidUnknownValues: false})`
10+
11+
### Fixed
12+
13+
- Updated lockfile to patch vulnerabilities ([#2669](https://github.com/typestack/class-validator/pull/2669))
14+
- Fixed a small grammatical error in the docs ([#2596](https://github.com/typestack/class-validator/pull/2596))
15+
16+
### Added
17+
18+
- Added `validateIf` option to all validators, providing a lot more flexibility in using conditional validation ([#1579](https://github.com/typestack/class-validator/pull/1579))
19+
- Added IsISO31661Numeric validator for country codes ([#2657](https://github.com/typestack/class-validator/pull/2657))
20+
- Added IsISO6391 validator for language codes ([#2626](https://github.com/typestack/class-validator/pull/2626))
21+
- Added more versions to IsUUID validator options. ([#2647](https://github.com/typestack/class-validator/pull/2647))
22+
-
23+
24+
## [0.14.4](https://github.com/typestack/class-validator/compare/v0.14.3...v0.14.4) (2026-02-25)
25+
26+
- Updated validator.js to 13.15.22 ([#2649](https://github.com/typestack/class-validator/pull/2649))
27+
528
## [0.14.3](https://github.com/typestack/class-validator/compare/v0.14.1...v0.14.3) (2025-11-24)
629

730
- Fixed a vulnerability by bumping validator.js ([#2638](https://github.com/typestack/class-validator/pull/2638) by [@weikangchia](https://github.com/weikangchia))

README.md

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,50 @@ validate(user, {
573573
There is also a special flag `always: true` in validation options that you can use. This flag says that this validation
574574
must be applied always no matter which group is used.
575575

576+
## Validation option validateIf
577+
578+
If you want an individual validaton decorator to apply conditionally, you can you can use the option `validateIf` available to all validators.
579+
This allows more granular control than the `@ValidateIf` decorator which toggles all validators on the property, but keep in mind that
580+
with great power comes great responsibility: Take care not to create unnecessarily complex validation logic.
581+
582+
```typescript
583+
class MyClass {
584+
@Min(5, {
585+
message: 'min',
586+
validateIf: (obj: MyClass, value) => {
587+
return !obj.someOtherProperty || obj.someOtherProperty === 'min';
588+
},
589+
})
590+
@Max(3, {
591+
message: 'max',
592+
validateIf: (o: MyClass) => !o.someOtherProperty || o.someOtherProperty === 'max',
593+
})
594+
someProperty: number;
595+
596+
someOtherProperty: string;
597+
}
598+
599+
const model = new MyClass();
600+
model.someProperty = 4;
601+
model.someOtherProperty = 'min';
602+
validator.validate(model); // this only validate min
603+
604+
const model = new MyClass();
605+
model.someProperty = 4;
606+
model.someOtherProperty = 'max';
607+
validator.validate(model); // this only validate max
608+
609+
const model = new MyClass();
610+
model.someProperty = 4;
611+
model.someOtherProperty = '';
612+
validator.validate(model); // this validate both
613+
614+
const model = new MyClass();
615+
model.someProperty = 4;
616+
model.someOtherProperty = 'other';
617+
validator.validate(model); // this validate none
618+
```
619+
576620
## Custom validation classes
577621

578622
If you have custom validation logic you can create a _Constraint class_:
@@ -662,7 +706,7 @@ export class CustomTextLength implements ValidatorConstraintInterface {
662706

663707
## Custom validation decorators
664708

665-
You can also create a custom decorators. Its the most elegant way of using a custom validations.
709+
You can also create a custom decorator. It's the most elegant way of using custom validations.
666710
Lets create a decorator called `@IsLongerThan`:
667711

668712
1. Create a decorator itself:
@@ -874,8 +918,10 @@ isBoolean(value);
874918
| `@IsLatitude()` | Checks if the string or number is a valid latitude coordinate. |
875919
| `@IsLongitude()` | Checks if the string or number is a valid longitude coordinate. |
876920
| `@IsMobilePhone(locale: string)` | Checks if the string is a mobile phone number. |
921+
| `@IsISO6391()` | Checks if the string is a valid ISO 639-1 officially assigned language code. |
877922
| `@IsISO31661Alpha2()` | Checks if the string is a valid ISO 3166-1 alpha-2 officially assigned country code. |
878923
| `@IsISO31661Alpha3()` | Checks if the string is a valid ISO 3166-1 alpha-3 officially assigned country code. |
924+
| `@IsISO31661Numeric()` | Checks if the string is a valid ISO 3166-1 numeric officially assigned country code. |
879925
| `@IsLocale()` | Checks if the string is a locale. |
880926
| `@IsPhoneNumber(region: string)` | Checks if the string is a valid phone number using libphonenumber-js. |
881927
| `@IsMongoId()` | Checks if the string is a valid hex-encoded representation of a MongoDB ObjectId. |
@@ -885,7 +931,7 @@ isBoolean(value);
885931
| `@IsTaxId()` | Checks if the string is a valid tax ID. Default locale is `en-US`. |
886932
| `@IsUrl(options?: IsURLOptions)` | Checks if the string is a URL. |
887933
| `@IsMagnetURI()` | Checks if the string is a [magnet uri format](https://en.wikipedia.org/wiki/Magnet_URI_scheme). |
888-
| `@IsUUID(version?: UUIDVersion)` | Checks if the string is a UUID (version 3, 4, 5 or all ). |
934+
| `@IsUUID(version?: UUIDVersion)` | Checks if the string is a UUID (version 1-8, nil, max, loose, all). Also accepts array of versions. |
889935
| `@IsFirebasePushId()` | Checks if the string is a [Firebase Push ID](https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html) |
890936
| `@IsUppercase()` | Checks if the string is uppercase. |
891937
| `@Length(min: number, max?: number)` | Checks if the string's length falls in a range. |

0 commit comments

Comments
 (0)