c# - Is it possible to validate a String Property to see if it is a valid date using Data Annotations? -


i have string property entity. putting date value ie "01/01/2000" via form. possible validate data entered see if valid ie:

assuming uk date format below:

"32/01/2000" not valid, "31/01/2000" valid, "test" not valid

my poco ef property code looks like:

[system.componentmodel.dataannotations.datatype(system.componentmodel.dataannotations.datatype.date, errormessage = @"not valid date")]   public virtual string dateofbirth 

should work .... or......

thanks.

you use regularexpression annotation, that's gonna make things messy least. you're best off converting property datetime.

here's how using regularexpression (shield eyes):

[regularexpression("@(^((((0[1-9])|([1-2][0-9])|(3[0-1]))|([1-9]))\x2f(((0[1-9])|(1[0-2]))|([1-9]))\x2f(([0-9]{2})|(((19)|([2]([0]{1})))([0-9]{2}))))$)", errormessage = @"not valid date")] public virtual string dateofbirth { get; set; } 

Popular posts from this blog

Php - Delimiter must not be alphanumeric or backslash -

Delphi interface implements -

java - How to create Table using Apache PDFBox -