Skip to content

Commit 056bfef

Browse files
committed
fix: include region in default error message for @IsPhoneNumber
1 parent 3230559 commit 056bfef

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

packages/express-cargo/src/validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ export function IsPhoneNumber(region?: CountryCode, message?: cargoErrorMessage)
475475
propertyKey,
476476
'isPhoneNumber',
477477
(value: unknown) => typeof value === 'string' && isValidPhoneNumber(value, region),
478-
message || `${String(propertyKey)} must be a valid phone number`,
478+
message || `${String(propertyKey)} must be a valid phone number${region ? ` for ${region}` : ''}`,
479479
),
480480
)
481481
}

packages/express-cargo/tests/validator/isPhoneNumber.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ describe('isPhoneNumber decorator', () => {
4242
.getValidators()
4343
?.find(v => v.type === 'isPhoneNumber')
4444

45+
it('should have region in default message', () => {
46+
expect(krRule?.message).toBe('phone must be a valid phone number for KR')
47+
})
48+
4549
it('should pass for valid Korean numbers', () => {
4650
expect(krRule!.validate('+821012345678')).toBeNull()
4751
expect(krRule!.validate('01012345678')).toBeNull()

0 commit comments

Comments
 (0)