Skip to content

Commit

Permalink
Regex checked only if ISO date was present in the string, it should c…
Browse files Browse the repository at this point in the history
…heck if the entire string is ISO Date
  • Loading branch information
vincent-chapron authored and NoNameProvided committed Nov 4, 2018
1 parent 064458a commit 5012464
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/validation/Validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 3 additions & 1 deletion test/functional/validation-functions-and-decorators.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5012464

Please sign in to comment.