question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validation fails for valid input with textual months followed by period (MMM. and MMMM.)

See original GitHub issue

Describe the bug In our date field, formats including MMM and MMMM cause the dayjs(value, format, strict=true).isValid() to return false for all values. image

Expected behavior IsValid() should return true

Information

  • Day.js Version: dayjs@^1.10.6: version “1.11.3”
  • OS: Windows 10
  • Browser: Chrome
  • Time zone: GMT+2 - Central European Summer Time

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
BePo65commented, Jul 11, 2022

I’ve made some tests and the issue could be easily fixed by adding a dot to the regex of matchWord (line 12 in customParseFormat.js). The line should be: const matchWord = /\d*[^-_:/.,()\s\d]+/0.

But there is a problem with this solution: unluckily the definitions for monthsShort in the locale definition files are not consistent. Some have a dot at the end, some not; I think that is the reason, why until now the dot is not part of the matchWord regex.

The customization example in the documentation does not have a dot after the monthShort so this looks like a recommendation to me.

There are a few issues concerning the parsing of dots, so perhaps it would be a good idea to make this change. But then we have to remove the dot from the monthShort in all locales (or remove the trailing dot by code in the function getLocalePart in ‘customParseFormat.js’ what would be my recommendation).

This is a decision to be made by @iamkun.

1reaction
BePo65commented, Jul 11, 2022

aah, you got it; the dot is handled by dayjs parsing as a format token and not as a ‘separator’.

At the moment I cannot test it on my sytem, so would you please try, if the dot in the format string can be escaped (surrounded by square brackets)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Laravel date_format Validation Fails on Textual Month
Laravel fails on date_format validation. The month does not match the format M Y. I have tried all PHP date formats from here...
Read more >
Date Input validation in a text box - Power Platform Community
my query here is I need to validate the input given by the user and show a popup to User to type date...
Read more >
<input type="month"> - HTML: HyperText Markup Language
The value is a string whose value is in the format " YYYY-MM ", where YYYY is the four-digit year and MM is...
Read more >
4.4. Validate Traditional Date Formats - O'Reilly
You want to validate dates in the traditional formats mm/dd/yy, ... You want to use a simple regex that simply checks whether the...
Read more >
Form Validation: Date and Time < JavaScript | The Art of Web
In this example, the date fields will only accept input that matches the pattern 'dd/mm/yyyy' (this could just as easily be changed to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found