Reputation: 45
When I use the following code I can only fill in (into an inputfield) as follows:
10/10/2014 i cannot fill in 10-10-2014 on firefox
NOTE when using a RegularExpression, it will still give an error when NOT using forward slashes / If the ReGex allows the - or any other symbol, 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>
Upvotes: 3
Views: 599
Reputation: 98840
As far as I see, yy
format specifier doesn't accept 4 digits year. It accepts only 2 digits of year.
Try to change your DataFormatString
like;
DataFormatString = "{0:dd.MM.yyyy}"
Upvotes: 1