Using the Relative Datetime Validator

Topics: Validation Application Block
May 11, 2007 at 7:22 PM
I have a requirement to validate that a person's Date of birth is not null and the person is atleast 18 years of Age. I have a property called DOB for a customer and I want to validate against this requirement.

I tried to use the Relative Datetime validator using the following XML config:
<property name="DOB">
<validator type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.AndCompositeValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="And Composite Validator">
<validator negated="false" messageTemplate="Your date of birth is either missing, in an incorrect format, or indicates that you are not at least 18 years old."
messageTemplateResourceName="" messageTemplateResourceType=""
tag="775" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.NotNullValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Not Null Validator" />
<validator lowerUnit="Year" upperUnit="Year" lowerBound="18"
lowerBoundType="Inclusive" upperBound="0" upperBoundType="Ignore"
negated="false" messageTemplate="Your date of birth is either missing, in an incorrect format, or indicates that you are not at least 18 years old."
messageTemplateResourceName="" messageTemplateResourceType=""
tag="775" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.RelativeDateTimeValidator, Microsoft.Practices.EnterpriseLibrary.Validation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
name="Relative Date Time Validator" />
</validator>
</property>


But, when I input the DOB as "1977-07-08", validation fails although the person is more than 18 years. What am i doing wrong?

Thanks,
Rajesh
May 12, 2007 at 12:47 AM
See your other thread: http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=10124

Regards,

Dave

_______________________________

David Hayden
Microsoft MVP C#