Adding validation
We have already touched on the subject of validation; there are some built-in functionalities in the input components as well as EditForm to handle validation.
One way to add validation to our form is to use DataAnnotations. By using data annotations, we don't have to write any custom logic to make sure the data in the form is correct; we can instead 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: Makes the field required
- Email: Will check that the entered value is an email address
- MinLength: Will check that the number of characters is not fewer than the value specified
- MaxLength: Will check that the number of characters is not exceeded
- Range: Will check that the value is within a certain range
There are many more annotations that can help...