Validation Framework in HDI

Validation Framework in HDI

Q) What is validation framework?
Ans) This framework helps to validate the form data in the server side.


Q) Which data is validated?
Ans) Every request to the server (GET or POST method) have some parameters which is generally known as formData. The formData is generally a JSON(JavaScript Object Notation) Object. If the formData is not a JSON Object then it is either a key value pair, which we generally refer as query parameters.

Example of request.


GET Method 


POST Method


POST Method using formData as JSON object



Q) How to configure the validation?
 Ans) Basically two files are to be considered for configuring the validation

  2. validation.xml


Q) What is
Ans) file is a property file. Any data validation regex can be configured here. See more about regular expression here
Example of

fileName=^[a-zA-Z0-9][a-zA-Z0-9 \\-\\.\\_\\~\\&\\(\\)\\[\\]\\:]+$

here email is the regex key ^[A-Za-z0-9._%’-]+@[A-Za-z0-9.-]+\\.[a-zA-Z0-9]+$ is regex value.


Q) What is validation.xml?
Ans) This file we have to map the url which we are going to validate. The url mapping has to be configured in the <mappings> tag

   <url pattern="/addUser.html" definition-file="createUsers.xml" />


This means the “/addUser.html” is the url whose request parameters needs to be validated. The definition-file attribute holds the xml file-name where the actual rules are configured.


Q) How rules are configured?
Ans)The rules are pretty simple. They are configured in the xml file with the request paramters key as the element and rules as the attribute.


For example the createUser.xml is configured as following

<?xml version="1.0" encoding="UTF-8"?>
   <action type="text" required="true"/>
   <name type="userName" />
   <age type="number" requiredIf="action" condition="=" value="add" minLength="6" maxLength="60"/>
    <qualification type="text"/>
    <dateOfRegistration type="date" maxLength="60" requiredIf="qualification" condition="=" value="engineer" />


Q) What is type attribute?
Ans) The type attribute holds the key defined in This attribute is not mandatory. If the request parameter is not empty then this regex is validated against the value of the request parameter.

The type attribute can have multiple key name separated by ,
eg type=”text,notNumber,notSpecialCharaters” here each key regex is validated and, if any of the key is found to be invalid the data is considered to be invalid.


Q) What is required attribute?
Ans) The required attribute is used when the request parameter should not be empty. In the above example the action and the name is required.
Q) What is minLength attribute?
Ans) The minLength attribute defines the minimum length (minimum characters) of the value for the request parameter.


Q) What is maxLength attribute?
Ans) The maxLength attribute defines the maximum length (maximum characters) of the value for the request parameter.


Q)What is length attribute?
Ans) When we know that the request parameter has to have the exact length then we can use this attribute.


Q) What is requiredIf attribute?
Ans) Sometime one parameter is dependent on another parameter . For example the dateOfRegistration is required if qualification is engineer.

With requiredIf attribute two more attribute condition and value need to be set

The condition attribute can have any operator eg. =, <= , >=, ==, != etc

The value attribute should have the value which is a rule.

<qualification type="text"/>
    <dateOfRegistration type="date" maxLength="60" requiredIf="qualification" condition="=" value="engineer" />