Adding validation
We have already touched on validation; there are some built-in functionalities in the input
components and EditForm
to handle validation.
One way to add validation to our form is to use DataAnnotations
. Using DataAnnotations, we don’t have to write any custom logic to ensure the data in the form is correct; instead, we can add attributes to the data model and let DataAnnotationsValidator
take care of the rest.
There are a bunch of DataAnnotations
instances in .NET already that we can use; we can also build our own annotations.
Some of the built-in data annotations are as follows:
Required
: This makes the field required.Email
: This will check that the entered value is an email address.MinLength
: This will check that the number of characters is not fewer than the value specified.MaxLength
: This will check that the number of characters is not exceeded.Range
: This will check that the value is within a specific...