Skip to content

Commit

Permalink
fix(isDate): fix isdate format validation (#1711)
Browse files Browse the repository at this point in the history
  • Loading branch information
flymans committed Sep 26, 2021
1 parent 5b649c6 commit b0d49bd
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
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
Expand Up @@ -10702,6 +10702,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 b0d49bd

Please sign in to comment.