DateTime "must be a date" only with a forward slash

When I use the following code, I can only fill (in the input field) like this:

10/10/2014 I can't fill 10-10-2014 on firefox

NOTE when using regex, it will still throw an error if NOT using slashes / If ReGex allows - or any other character, C # itself will still give "must be a date"

Model:

[Required(ErrorMessage = "Field is Required")]
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd.MM.yy}", ApplyFormatInEditMode = true)]
public DateTime Bday { get; set; }

      

Create.cshtml

<div class="editor-field">
    @Html.EditorFor(model => model.Bday)
    @Html.ValidationMessageFor(model => model.Bday)
</div>

      

+3


source to share


1 answer


As I understand it, yy

the format specifier
does not accept 4 digits of the year. It only accepts 2 digits for the year.

Try changing your DataFormatString

like;



DataFormatString = "{0:dd.MM.yyyy}"

      

+1


source







All Articles