.net 验证应用程序块中的验证日期时间
如何通过验证应用程序块验证DateTime,使其不超过DateTime。现在.net 验证应用程序块中的验证日期时间,.net,validation,enterprise-library,.net,Validation,Enterprise Library,如何通过验证应用程序块验证DateTime,使其不超过DateTime。现在 谢谢。您可以使用正则表达式进行验证,只需选择时间格式我认为使用验证应用程序块进行验证的最简单方法是创建一个返回日期时间的属性。请不时使用属性比较验证程序 自我验证也可以让你做你想做的事。属性比较验证器允许您将逻辑外部化,但是仅仅为了比较而公开属性感觉有点错误 实施 public class Person { public DateTime Now { get { return DateT
谢谢。您可以使用正则表达式进行验证,只需选择时间格式我认为使用验证应用程序块进行验证的最简单方法是创建一个返回日期时间的属性。请不时使用属性比较验证程序 自我验证也可以让你做你想做的事。属性比较验证器允许您将逻辑外部化,但是仅仅为了比较而公开属性感觉有点错误 实施
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>
您可以使用。以下假设我们没有超过140岁的人(到目前为止,死亡时为122岁)
我想对DateOfBirth字段使用验证器。因此,我不想接受大于系统日期的日期。如何检查?问题是关于作为企业库一部分的验证应用程序块。@Vadim我明白了,但使用regext更容易问题不是关于格式…而是关于日期时间值小于或等于另一个日期时间值。
[RelativeDateTimeValidator(-140, DateTimeUnit.Years, 0, DateTimeUnit.Second,
MessageTemplate = "Sorry, no predicted births allowed.")]
public DateTime DateOfBirth
{ get; set;}