Skip to content

Commit

Permalink
fix(validators): fix isdate format validation
Browse files Browse the repository at this point in the history
  • Loading branch information
flymans committed Aug 20, 2021
1 parent 8c4b3b3 commit 6e3c9f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/isDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const default_date_options = {
};

function isValidFormat(format) {
return /(^(y{4}|y{2})[\/-](m{1,2})[\/-](d{1,2})$)|(^(m{1,2})[\/-](d{1,2})[\/-]((y{4}|y{2})$))|(^(d{1,2})[\/-](m{1,2})[\/-]((y{4}|y{2})$))/gi.test(format);
return /(^(y{4}|y{2})[.\/-](m{1,2})[.\/-](d{1,2})$)|(^(m{1,2})[.\/-](d{1,2})[.\/-]((y{4}|y{2})$))|(^(d{1,2})[.\/-](m{1,2})[.\/-]((y{4}|y{2})$))/gi.test(format);
}

function zip(date, format) {
Expand Down
19 changes: 19 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -10674,6 +10674,25 @@ describe('Validators', () => {
'2020/03-15',
],
});
test({
validator: 'isDate',
args: [{ format: 'MM.DD.YYYY', delimiters: ['.'], strictMode: true }],
valid: [
'01.15.2020',
'02.15.2014',
'03.15.2014',
'02.29.2020',
],
invalid: [
'2014-02-15',
'2020-02-29',
'15-07/2002',
new Date(),
new Date([2014, 2, 15]),
new Date('2014-03-15'),
'29.02.2020',
],
});
});
it('should be valid license plate', () => {
test({
Expand Down

0 comments on commit 6e3c9f3

Please sign in to comment.