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

isValid() not working properly with format as second parameter #4462

Closed
brunosiqueira opened this issue Mar 1, 2018 · 2 comments
Closed

Comments

@brunosiqueira
Copy link

brunosiqueira commented Mar 1, 2018

Description of the Issue and Steps to Reproduce:
isValid() has a weird behavior. Using the browser (momentjs site open), if I type:

moment('2018-dkjsnaksaj x-null').isValid() >> false

But if I set the format of the string as a second parameter, then I get:

moment('2018-dkjsnaksaj x-null', 'YYYY-M-DD').isValid() >> true

Please include the values of all variables used.

Environment:

Chrome 64.0.3282.186
MacOS High Sierra
Both the browser and the OS are important to us, particularly if you have an unsual environment like an IOT application.

Other information that may be helpful:
Thu Mar 01 2018 15:15:41 GMT-0300 (-03)
VM258:2 01/03/2018 15:15:41
VM258:3 180
VM258:4 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36
VM258:5 2.20.1
undefined

@prendradjaja
Copy link

The parser is very forgiving unless strict mode is enabled. See docs here and here for more details.

You probably just want to enable strict mode by passing true as the last argument.

moment('2018-dkjsnaksaj x-null', 'YYYY-M-DD', true).isValid() >> false

@marwahaha

@marwahaha
Copy link
Member

Yeah, strict mode will help here. There's more info in this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants