0

I'm developing and asp.net app and i'm using data annotations to validate my Input model. In this model, I have one field of type DateTime, and I'd like to know how could I customize the message when the user set an date value invalid.

My property in my model:

[Required(ErrorMessage = "Informe sua data de nascimento.")]
[MinAge(Idade = 18, ErrorMessage = "Você deve possuir no mínimo 18 anos para se cadastrar neste website.")]
public virtual DateTime DataNascimento { get; set; }

My model is thowing a message like this: "The value '45/64/5646' is not valid for DataNascimento."

If you could help me I appretiate!

PS: The messages of validators are in pt-br (because it'll be the language of the application)

Thanks a lot

Felipe Oriani
  • 37,948
  • 19
  • 131
  • 194

1 Answers1

-1

I think what you need there is a regular expression that actually checks the format of the date time. (Note: I think this is the correct RegEx format.

[RegularExpression(@"^([0]?[1-9]|[1|2][0-9]|[3][0|1])[./-]([0]?[1-9]|[1][0-2])[./-]([0-9]{4}|[0-9]{2})$", ErrorMessage = "The date is invalid.")]
Flesrouy
  • 684
  • 3
  • 10