From 5012464b67dd99847afc7774bb2983cd47fe75fc Mon Sep 17 00:00:00 2001 From: Vincent CHAPRON Date: Thu, 1 Nov 2018 14:20:13 +0100 Subject: [PATCH] Regex checked only if ISO date was present in the string, it should check if the entire string is ISO Date --- src/validation/Validator.ts | 2 +- test/functional/validation-functions-and-decorators.spec.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/validation/Validator.ts b/src/validation/Validator.ts index b052b9a9a3..692a12d8bd 100644 --- a/src/validation/Validator.ts +++ b/src/validation/Validator.ts @@ -341,7 +341,7 @@ export class Validator { * Checks if a given value is a ISOString date. */ isDateString(value: any): boolean { - const regex = /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|\+[0-2]\d(?:\:[0-5]\d)?)?/g; + const regex = /^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|\+[0-2]\d(?:\:[0-5]\d)?)?$/g; return this.isString(value) && regex.test(value); } diff --git a/test/functional/validation-functions-and-decorators.spec.ts b/test/functional/validation-functions-and-decorators.spec.ts index a45d3a4fb4..1d06a71d81 100644 --- a/test/functional/validation-functions-and-decorators.spec.ts +++ b/test/functional/validation-functions-and-decorators.spec.ts @@ -619,7 +619,9 @@ describe("IsDateString", function() { 2, null, undefined, - "text" + "text", + "text2018-01-04T08:15:30+04", + "2018-01-04T08:15:30Ztext", ]; class MyClass {