Data validation

Data or input validation in MDriven ensures that data entered by users is correct, consistent, and conforms to the business rules of the application before being processed or persisted in the database.

Data validation is important for three reasons

  1. Data Integrity
  2. Enforcing business rules
  3. Data Security

Common types of Data Validation MDriven uses:

  • Required Fields: self.FirstName.IsEmpty implies "FirstName is required" (Field should not be left empty)
  • Data type validation: this can be by ensuring the correct data type in selected for the model attribute (String, Date, Datetime, decimal, Float, Blob e.t.c).
  • Range validation (self.DayOfBirth > 0) and (self.DayOfBirth < 32). The system only expects values between 0 - 31 excluding 0 and 32.
  • Format validation such regular expressions for emails self.EmailAddress.regExpMatch('^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,3}$').
  • Conditional validations.
Documentation Data validation 1727976784514.png
  1. Click on Add Validation
  2. Use the popup window to create the Validation Rule Name, the OCL Expression, and the Message. You should see once the constraint has been violated.
  3. To put the validation rule into effect, right click on the column name on the ViewModel and scroll down to select Validation rules, then click the validation rule you want for that column.
Documentation Data validation 1727977944529.png


The client will then provide feedback to the user entering data into the system once the validations are violated.

Documentation Data validation 1727976227553.png

Validation Implementation in MDriven

In MDriven, validation is integrated into the model using Object Constraint Language (OCL). OCL allows developers to write declarative rules that validate data against predefined criteria.

  1. Model-Level Validation: OCL constraints can be defined at the class or attribute level to ensure that data entered into any instance of the class adheres to the rules. This can be referred to as server-side validation.
  2. UI-Level Validation: In addition to the model-level constraints, MDriven's user interface can provide real-time feedback to users as they input data, highlighting fields that fail validation before the form can be submitted as shown above. This is also referred to as client-side validation.
This page was edited 66 days ago on 10/17/2024. What links here