日期验证器,使用 Zend Framework 验证日期是否大于或等于今天
$form = new Zend_Form();
$mockDate = new Zend_Form_Element_Text('mock');
$mockDate->addValidator(???????);
$form->addElements(array($mockDate));
$result = $form->isValid();
if ($result) echo "YES!!!";
else echo "NO!!!";
假设该元素采用日期格式。如何确定给定的日期大于或等于今天?
$form = new Zend_Form();
$mockDate = new Zend_Form_Element_Text('mock');
$mockDate->addValidator(???????);
$form->addElements(array($mockDate));
$result = $form->isValid();
if ($result) echo "YES!!!";
else echo "NO!!!";
Assumption that the element is in a date format. How do I determine that the date given is greater than or equal to today?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这更好,因为使用标准化的 Zend_Date 方法来检查日期,另一个 awsner 用户使用可以评估为不可预测值的字符串比较......
that's better because uses standardized Zend_Date methods to check dates, the other awsner user a string comparison that can evaluate to impredictable values...
您可以创建一个简单的验证器来执行此操作:
并将其添加到元素中:
您可能想使用
Zend_Date
用于日期本地化和其他好处。要创建自定义验证,请查看 Zend 的编写验证器的手册。
You can create a simple validator to do this:
And add it to the element:
You probably want to check the date with
Zend_Date
for localization of dates and further benefits.For creating custom validates, take a look at writing validators from Zend´s manual.
这个问题相当老了。在当前版本的 ZF2 中,无需编写新的验证器。只需添加一个过滤器/验证器,如下所示:
它就可以完成工作。还有一个名为“inclusive”的选项,如果设置为“true”(在 GreaterThan 的“选项”中),将允许“今天”成为有效日期
The question is rather old. In the current version of ZF2 it is not necessary to write new validators. Simply add a filter / validator like this:
And it does the job. There is also an option called 'inclusive' which if set to 'true' (in the 'options' of GreaterThan), will allow 'today' to be a valid date