Hello All!
How to validate DateTime by Validation Application Block, to not be more than DateTime.Now?
thanks.
Hello All!
How to validate DateTime by Validation Application Block, to not be more than DateTime.Now?
thanks.
You can use Regex for validation just choose time format http://regexlib.com/REDetails.aspx?regexp_id=504
I think the easiest way to do this using the Validation Application Block would be to create a property that returns DateTime.Now and then use a Property Comparison Validator.
SelfValidation would also let you do what you want. The Property Comparison Validator lets you externalize the logic but it feels a bit wrong to expose a property just to compare against.
Implementation
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>