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" />

Regular Expression

Regular Expression in Java

Regular Expression or popularly known as Regex is a powerful features and help developers in many ways.
The following are some special characters with their behaviour

. Match any character except newline

\w Match any alphanumeric character

\s Match any whitespace character

\d Match any digit

\b Match the beginning or end of a word

^ Match the beginning of the string

$ Match the end of the string


* Repeat any number of times

+ Repeat one or more times

? Repeat zero or one time

{n} Repeat n times

{n,m} Repeat at least n, but no more than m times

{n,} Repeat at least n times


\W Match any character that is NOT alphanumeric

\S Match any character that is NOT whitespace

\D Match any character that is NOT a digit

\B Match a position that is NOT the beginning or end of a word

[^x] Match any character that is NOT x

[^aeiou] Match any character that is NOT one of the characters aeiou

Construct Matches

[abc] Matches a, or b or c. This is called a simple class, and it matches any of the characters in the class.
[^abc] Matches any character except a, b, and c. This is a negation.
[a-zA-Z] Matches any character from a to z, or A to Z, including a, A, z and Z. This called a range.
[a-d[m-p]] Matches any character from a to d, or from m to p. This is called a union.
[a-z&&[def]] Matches d, e, or f. This is called an intersection (here between the range a-z and the characters def).
[a-z&&[^bc]] Matches all characters from a to z except b and c. This is called a subtraction.
[a-z&&[^m-p]] Matches all characters from a to z except the characters from m to p. This is also called a subtraction.


1. Username Regular Expression Pattern

2. Password Regular Expression Pattern
(?=.*\d) # should have one digit from 0-9
(?=.*[a-z]) # should have one lowercase characters
(?=.*[A-Z]) # should have one uppercase characters
(?=.*[@#$%]) # should have one special symbols in the list "@#$%"
. # match anything with previous condition checking
{6,20} # length at least 6 characters and maximum of 20

3. Email Regular Expression Pattern

4 Image File Extension Regular Expression Pattern

5.Time in 24-Hour Format Regular Expression Pattern

6. Date Format (dd/mm/yyyy) Regular Expression Pattern

Reference- internet