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