Data Attributes and Validation

Learn about adding validations to your forums with the help of data attributes in your model classes.

We'll cover the following

Introduction

Data attributes allow you to enforce different rules against a property. These rules can include:

  • Requiring users to enter some data and not leaving a field blank
  • Defining maximum field length
  • Only allowing specific characters to be entered in a specific order

The framework will throw errors if the data entered for the fields does not conform to the specified rules, thus enabling validation.

Code in action

The following code illustrates how attributes might be added to the User controller from the previous lesson

Get hands-on with 1200+ tech skills courses.