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

Check if a string is a valid date with a given format #84

Open
loota opened this issue Sep 12, 2016 · 3 comments
Open

Check if a string is a valid date with a given format #84

loota opened this issue Sep 12, 2016 · 3 comments
Labels

Comments

@loota
Copy link

loota commented Sep 12, 2016

It would be very useful to be able to check if a string is a valid date. It is a very common use case to get a date string from a form or from an external service.

Example from moment.js: moment('29.2.2013', 'DD.MM.YYYY').isValid()

Code which I believe moment.js uses for this:
https://github.com/moment/moment/blob/c587bf0063c18214238ca83f3f9c6170daf25bed/src/lib/create/from-string.js

@fightbulc
Copy link
Owner

Howdy. Will take a look.

@loota
Copy link
Author

loota commented Sep 13, 2016

Respect\Validation also validates this:

validate('30.6.2015'), //true v::date('d.m.Y')->validate('31.6.2015'), //false v::date('d.m.Y')->validate('29.2.2015'), //false v::date('d.m.Y')->validate('29.2.2016') //true ); ?>

The code seems to be here: https://github.com/Respect/Validation/blob/master/library/Rules/Date.php

@RuslanMelnychenko
Copy link

The function isValidDate is there, but it is private, you can make it public.
https://github.com/fightbulc/moment.php/blob/master/src/Moment.php#L1306-L1406

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

No branches or pull requests

3 participants