1
A
回答
0
您可以使用正则表达式进行验证只是选择时间格式http://regexlib.com/REDetails.aspx?regexp_id=504
0
我想做到这一点使用的验证应用程序块将创建一个返回DateTime.Now属性,然后使用性能对比验证的最简单方法。
SelfValidation还可以让你做你想做的。 Property Comparison Validator允许您将逻辑外部化,但仅仅为了比较而暴露属性感觉有点不对。
实施
public class Person
{
public DateTime Now
{
get { return DateTime.Now; }
}
public DateTime BirthDate
{
get;
set;
}
}
<type assemblyName="MyApp.Entities, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="MyApp.Entities.Person">
<ruleset name="MyRuleSet">
<properties>
<property name="BirthDate">
<validator operator="LessThanEqual" propertyToCompare="Now" negated="false"
messageTemplate="I don't know nothin' about birthin' no babies in the future." messageTemplateResourceName=""
messageTemplateResourceType="" tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.PropertyComparisonValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null"
name="Property Comparison Validator" />
</property>
</properties>
</ruleset>
</type>
0
可以使用RelativeDateTimeValidator。下面假设我们没有140岁以上的人(worlds oldest,到目前为止,在死亡时是122)。
[RelativeDateTimeValidator(-140, DateTimeUnit.Years, 0, DateTimeUnit.Second,
MessageTemplate = "Sorry, no predicted births allowed.")]
public DateTime DateOfBirth
{ get; set;}
相关问题
- 1. 验证应用程序块 - 如何使用验证metada类
- 2. 验证应用程序块验证NetTiers实体
- 3. C#模型验证 - 验证应用程序块或DataAnnotations?
- 4. 验证应用程序块的对象验证不规则集
- 5. 验证应用程序块 - 自定义验证程序 - 消息模板
- 6. 验证iOS应用程序
- 7. 使用ASP.NET MVC4应用程序验证应用程序块
- 8. 在rhomobile应用程序中验证
- 9. 使用验证程序类验证DataAnnotations
- 10. 应用程序验证许可证enforement?
- 11. 使用验证应用程序块验证集合至少有一个项目
- 12. 如何验证DateTime
- 13. 验证通过非Ruby应用程序的验证身份验证
- 14. 验证程序
- 15. MVC中对DateTime的验证
- 16. 要选择哪个验证框架:Spring验证或验证应用程序块(Enterprise LIbrary 4.0)?
- 17. 验证在道场/ PHP应用程序
- 18. 验证执行.NET应用程序时的验证码签名
- 19. 应用程序未通过验证码验证?
- 20. 如何验证Worklight 5.0.5上的应用程序身份验证
- 21. jsr-303验证春天mvc应用程序不验证
- 22. INVALID_APP_CREDENTIAL:应用程序验证失败,Firebase身份验证
- 23. 在自定义验证中使用默认验证程序
- 24. 验证SQL文件 - SQL验证程序
- 25. Hibernate验证程序验证集
- 26. ember-cp验证条件验证程序
- 27. 验证与直列验证方法和验证程序类
- 28. 在MVC应用程序中结合ASP.NET成员身份验证和HTTP验证
- 29. 如何在整个Web应用程序中持续验证身份验证
- 30. 块域验证?
我想为DateOfBirth field.so使用验证程序,因此我不想接受大于系统日期的日期。我如何检查? – Wilson 2010-05-18 11:37:53