Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(validators): fix isdate format validation #1711

Merged
merged 1 commit into from Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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