使用Symfony2验证日期范围 [英] Date range validation with Symfony2

查看:92
本文介绍了使用Symfony2验证日期范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Symfony中添加带注释的约束,以使日期处于该范围内,但是不能使用min显式指定此范围.和最大年份应介于当前年份(减去当前年份或数字)和所指示的最小值之间.例如,如果我键入一个日期,现在的日期必须在2010/1960之间,但应从当前的10年获得2010.这可以在Symfony中以任何方式完成吗?

I want to add a constraint with annotation in Symfony for a date falls within the range, but this range can not be specified explicitly with min. and max. The year should be between the current year (by subtracting the current year or number) and the minimum indicated. For example, if I type a date now must be between 2010/1960, but 2010 should be obtained from the current year-10. This can be done in any way in Symfony?

推荐答案

是的,您可以按照以下说明创建自定义验证约束:

Yes it is possible, you should create a custom validation constraint as explained here :

http://symfony.com/doc/current/cookbook/validation/custom_constraint.html

这篇关于使用Symfony2验证日期范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆