From 8bd9640beed15917b40f8203427b829eaa8b9397 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Fri, 26 Apr 2024 11:02:54 +0200 Subject: [PATCH] :sparkles: update phone number validation --- dist/Notary/Contact.js | 4 ++-- src/Notary/Contact.ts | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/dist/Notary/Contact.js b/dist/Notary/Contact.js index a373032..7ac40c2 100644 --- a/dist/Notary/Contact.js +++ b/dist/Notary/Contact.js @@ -96,9 +96,9 @@ __decorate([ groups: ["createCustomer"], message: "Numéro de téléphone ne peut pas être vide", }), - (0, class_validator_1.Matches)(/^\+[1-9]{2,3}[0-9]{9}$/, { + (0, class_validator_1.IsPhoneNumber)(undefined, { groups: ["createCustomer", "updateCustomer"], - message: "Le numéro de téléphone doit être au format 0X XX XX XX XX ou +33X XX XX XX XX", + message: "Numéro de téléphone incorrect", }), __metadata("design:type", Object) ], Contact.prototype, "cell_phone_number", void 0); diff --git a/src/Notary/Contact.ts b/src/Notary/Contact.ts index 9e9bbd5..1a5d1d2 100644 --- a/src/Notary/Contact.ts +++ b/src/Notary/Contact.ts @@ -5,7 +5,7 @@ import { IsEmail, IsNotEmpty, IsOptional, - Matches, + IsPhoneNumber, NotEquals, ValidateNested, } from "class-validator"; @@ -68,10 +68,9 @@ export default class Contact extends ContactCustomer { groups: ["createCustomer"], message: "Numéro de téléphone ne peut pas être vide", }) - @Matches(/^\+[1-9]{2,3}[0-9]{9}$/, { + @IsPhoneNumber(undefined, { groups: ["createCustomer", "updateCustomer"], - message: - "Le numéro de téléphone doit être au format 0X XX XX XX XX ou +33X XX XX XX XX", + message: "Numéro de téléphone incorrect", }) public override cell_phone_number?: string | null = null;