I use the following model (part):
[DataType(DataType.PhoneNumber), Display(Name = "Phone #")]
public string PhoneNo { get; set; }
[DataType(DataType.PhoneNumber), Display(Name = "Fax #")]
public string FaxNo { get; set; }
[DataType(DataType.EmailAddress), Display(Name = "Email")]
public string Email { get; set; }
and View:
<div class="form-group">
@Html.LabelFor(model => model.PhoneNo, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.PhoneNo, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.PhoneNo, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.FaxNo, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.FaxNo, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.FaxNo, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Email, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Email, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Email, "", new { @class = "text-danger" })
</div>
</div>
but when I try to type trash data (i.e. "blablabla"), Email field validator works, but phone validators are not. Why?