Created
March 21, 2013 04:18
-
-
Save notomato/5210653 to your computer and use it in GitHub Desktop.
Custom validator example.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validator::add('validShippingDate', function($value, $format, $options) { | |
$validDates = array( | |
date('Y-m-d', time()), | |
date('Y-m-d', time() + 60*60*24), | |
date('Y-m-d', time() + 2*60*60*24), | |
date('Y-m-d', time() + 3*60*60*24), | |
date('Y-m-d', time() + 4*60*60*24), | |
date('Y-m-d', time() + 5*60*60*24), | |
date('Y-m-d', time() + 6*60*60*24), | |
date('Y-m-d', time() + 7*60*60*24) | |
); | |
foreach ($validDates as $index => $date) { | |
if (date('N', strtotime($date) >= 6)) { | |
unset($validDates[$index]); | |
} | |
} | |
if (in_array(date('Y-m-d', strtotime($value)), $validDates)) { | |
return true; | |
} | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment