How can I make the form first name input field not accept empty strings with space characters " "
<form asp-action="SaveRegistration" autocomplete="off">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="FirstName" class="control-label"></label>
<input asp-for="FirstName" class="form-control" />
<span asp-validation-for="FirstName" class="text-danger"></span>
</div>
Model:
public class ContactInfo
{
[Required(ErrorMessage = "This field is required")]
[StringLength(50)]
[DisplayName("First name")]
public string FirstName { get; set; }
}
With [Required] attribute the user can still submit with a string with just space characters " "
I know it's a simple question, but I am novice in ASP.NET MVC
[StringLength]and.. what deters you from using@Html.TextBoxFor()?Html.TextBoxForbetter than<input asp-for="FirstName"?MinLengthhelps? I want to prevent user from entering string of just space characters, I don't want to restrict to a minimum length[Required(AllowEmptyStrings = false)]- is this work? Sounds like you can write customRequiredAttributewithIsNullOrWhiteSpacecheck.