I have an EditForm with some InputText. Some of the textboxes are required and as such in their class are declared using the [Required]. However some of them also have a [StringLength(100, ErrorMessage = "Forename is too long")]. When the forename is too long in the textbox then the message below is as I have written it 'Forename is too long'. When I have a RegularExpression [RegularExpression(@"^\w+[.]\w+[@]\w+[.]\w+$", ErrorMessage = "Email must follow fred.example@live.com structure")]. Then the error message is 'Email must follow fred.example@live.com structure'. So I though it would be easy to add some validation to the [Required] by putting : [Required(ErrorMessage = "This is required")]. However the message displayed is 'The Surname field is required.'. How can I edit this message because what I have done has clearly not done the job.
<EditForm Model=@newUser OnValidSubmit="HandleSubmit">
<DataAnnotationsValidator />
@* <ValidationSummary/>*@
<label for="userForename">Forename:</label>
<InputText id="userForename" @bind-Value="@newUser.Forename"></InputText>
<ValidationMessage For="@(() => newUser.Forename)" />
<label for="userSurname">Surname:</label>
<InputText id="userSurname" @bind-Value="@newUser.Surname"></InputText>
<ValidationMessage For="@(() => newUser.Surname)" />
<label for="userEmailAddress">Email Address:</label>
<InputText id="userEmailAddress" @bind-Value="@newUser.EmailAddress"></InputText>
<ValidationMessage For="@(() => newUser.EmailAddress)" />
<button type="submit" class="btn-primary">Add</button>
</EditForm>