Skip to content

Commit 5012464

Browse files
vincent-chapronNoNameProvided
authored andcommitted
Regex checked only if ISO date was present in the string, it should check if the entire string is ISO Date
1 parent 064458a commit 5012464

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/validation/Validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export class Validator {
341341
* Checks if a given value is a ISOString date.
342342
*/
343343
isDateString(value: any): boolean {
344-
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;
344+
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;
345345
return this.isString(value) && regex.test(value);
346346
}
347347

test/functional/validation-functions-and-decorators.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,9 @@ describe("IsDateString", function() {
619619
2,
620620
null,
621621
undefined,
622-
"text"
622+
"text",
623+
"text2018-01-04T08:15:30+04",
624+
"2018-01-04T08:15:30Ztext",
623625
];
624626

625627
class MyClass {

0 commit comments

Comments
 (0)