-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Date format validation rule #1192
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
Date format validation rule #1192
Conversation
+1 for this, I've been needing it a lot lately |
Genius, thanks! |
I see some extra commits in this pull :/ |
Well yeah but it's all related to what he added, no ? |
I think I messed up merging a little bit - because I have two remotes, @daylerees Would you mind simply squashing my commits into one? That would keep the history clean. I don't care that much about my original commits being there (although you could of course have me as author in the squashed one). ;) |
Ah, sheesh. When merging this, please make sure the language key is added to all then-existent language files! |
+1 to this pull request. This should be in there. |
+10! |
looks good |
Manual merging this. Thanks Franz! |
@daylerees Some ugly files are still in the repo tree. |
Hmm, not sure where they came from, but they have been removed now :) cheers mate. |
PHP's date_parse_from_format is either broken or is intentionally far too lenient to use for validating formatting on simple date parts. You can not, for example, validate a 2 digit year vs 4 digit year, or a month with or without leading zeroes. For example, if you set up the rule: 'year' => 'date_format:Y',
'month' => 'date_format:m' and pass the following: ['year'=>'16', 'month'=>'3'] It will not report any errors. You would expect it to fail on both, since the year should be 4 digits and the month should include a leading 0. |
Hello @franzliedke ,@mjbrunme I'm facing a related issue with the The rule as: Any thoughts how we can restrict this and end up with valid year ? |
0020 is a valid year
… On Apr 25, 2017, at 4:18 PM, mansouralex ***@***.***> wrote:
Hello @franzliedke ***@***.*** I'm facing a related issue with the Y format:
The rule as: date_format:d-m-Y and it's accepting such date: "21-12-0020"
Any thoughts how we can restrict this and end up with valid year ?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I used CARBON. http://carbon.nesbot.com/docs/ It's made easier, you can install using the caomposer and call the object in your controller. |
@satodu I'm already aware and using CARBON. But how do you suggest we can employ it in this case? |
The date is a valid date. If it's not for your use case I suggest you
create your own validation rule.
…On 25 Apr 2017 10:19 am, "mansouralex" ***@***.***> wrote:
Hello @franzliedke <https://github.com/franzliedke> ***@***.***
<https://github.com/mjbrunme> I'm facing a related issue with the Y
format:
The rule as: date_format:d-m-Y and it's accepting such date: "21-12-0020"
Any thoughts how we can restrict this and end up with valid year ?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1192 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AKtrcHsSGcUtGKtRvp1y8JB4gnIuen0Wks5rzbqogaJpZM4AJGcS>
.
|
$dt = Carbon::createFromDate(0020, 10, 6); |
This allows for validating a PHP date format.
Rules would look like this:
Note the quotes wrapping the value so that the colon does not count as parameter separator.
Everything documented and properly unit-tested.