Skip to content

Instantly share code, notes, and snippets.

@notomato
Created March 21, 2013 04:18
Show Gist options
  • Save notomato/5210653 to your computer and use it in GitHub Desktop.
Save notomato/5210653 to your computer and use it in GitHub Desktop.
Custom validator example.
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