Enabling whitelist validation using validation attributes
Web developers can take advantage of the built-in validation framework that ASP.NET Core provides. The intrinsic Data Annotation Attribute (DAA) allows you to validate values that are bound to model properties. Validating against a matching pattern enables us to filter input, and we can specify the regular expression as our whitelist. If the model's value does not resemble a regular expression, it will be considered bad input.
There are plenty of validation attributes that you can use to build business rules around your model, but for us to implement whitelist validation, the RegularExpression
attribute must come into play.
In this recipe, we will use the RegularExpression
attribute to define a pattern for our model properties to whitelist characters.
Getting ready
Open the command shell and download the sample Online Banking app by cloning the ASP.NET Secure Coding Cookbook repository:
git clone https:/...