You are on page 1of 8

Field constraints

1
Document history
Version Date Author Changes made
1.0 10/12/2009 Laurent SEYMAN Document creation
1.1 7/16/2012 Laurent SEYMAN New template
1.2 8/1/2013 Laurent SEYMAN Update for EasyVista 2013

This document explains the implementation of field constraints in EasyVista.

2
Index
A. Principle of functioning.............................................................4

B. Creating a field constraint.........................................................5

C. Regular expressions..................................................................6
C.1. Definition.......................................................................................................6
C.2. Building a regular expression....................................................................6

D. Summary of special characters used


in regular expressions..............................................................7

E. Some examples of regular expressions..................................8

3
A. Principle of functioning
The constraints-management system was implemented so that a valid entry format can be defined for each field for which this is
desired. This mechanism was positioned at the level of the Administration module, menu Parameters / Field Constraints.
This menu displays a list of fields and the associated entry constraints.

It is possible to create a new constraint using the button located on the grid, or to edit an existing constraint using the
wizard:

4
B. Creating a field constraint

Clicking on the button launches the wizard for entering a constraint. Then, you should enter a name for the constraint,
select the table in the drop-down list, then selects the list of associated fields. Once this has been done, the constraint should be
defined using a regular expression.

Before inserting or modifying data, the existing constraints will be checked. If there is an error, the user will see an error
message specifying the field that caused the problem.

5
C. Regular expressions

C.1. Definition
Regular expressions are patterns, created using ASCII characters, for manipulating character strings, meaning for finding
portions of the string that correspond to the pattern.

C.2. Building a regular expression


Regular expressions are used for searching for occurrences (meaning a series of characters corresponding to what is searched
for), using a series of special characters. The regular expression itself is therefore a character string containing special
characters and standard characters.

The symbols *, + and ?, respectively "zero or several", "one or several" and "one or nothing", provide the concept of numbers.
abc+ : string containing ab followed by one or several c ( abc , abcc ...)

abc* : string containing ab followed by zero c or more ( ab , abc ...)

abc? : string containing ab followed by zero or one c ( ab or abc )

Braces {X,Y} are used to limit numbers.


abc{2} : string containing ab followed by two instances of c ( abcc )

abc{2,} : string containing ab followed by two c or more ( abcc etc..)

abc{2,4} : string containing ab followed by 2, 3 or 4 instances of c ( abcc ... abcccc )

Note:
The first number of the limit ( {0,2} , but not {,2} ) is obligatory. The symbols seen previously * , + and ? , are
equivalent to {0,} , {1,} and {0,1} .

Parentheses ( ) are used for representing a sequence of characters.


"a(bc)*": string containing a followed by zero bc or more

The vertical bar | behaves as the OR operator


one|the : string containing one or the

(one|the) dog : string containing one dog or the dog

(a|b)+ : string containing a sequence of a or b .


Ex: aab or bab
3000|([1-2][0-9]{3})|([1-9][0-9]{2}) : number included between 100 and 3000
3000 => number 3000
[1-2][0-9]{3} => number included between 1000 and 2999
[1-9][0-9]{2} => number included between 100 and 999
Note: Parentheses are optional because the | behaves as an expression separator

The dot . indicates any character (once)


.{3}: string containing 3 characters

A.{4} : string starting with a letter A and with a length of 5 characters; the last 4 being any character

Square brackets [ ] define a list of characters that are allowed (or forbidden). The - sign defines an interval. The character ^ after
the first square bracket indicates prohibition.
6
[abc]: string containing an a, un b, or a c

[a-z]: string containing a character between a and z

[^a-zA-Z]+: string that does not contain letters

Note:
To search for a character that is one of the special characters, you must precede it with a backslash \ (except
between square brackets). A backslash must therefore be doubled: \\ .
The backslash \ must never be placed last when it is between square brackets, otherwise the expression is
erroneous because it considers that you are trying to escape the closing square bracket ]
To write a letter in uppercase or a backslash
Do not write [A-Z\]
But [\A-Z]

Inside the square brackets, each character represents what it is. To represent a ] ] you must put it first (or after a ^ if it is a
prohibition), a - is placed first or last.

A slash / must always be escaped using a backslash \ . Ex: if you wish to write all letters and the / are allowed , you
would write: [a-zA-Z\/]+.

A backslash \ must never be placed after or before a slash / if you wish to allow it.
[\+?{}.]: string which contains one of these six characters

[]-]: string containing the character ] or the character -

[a-zA-Z\/] : string containing a letter or a slash /

D. Summary of special characters used in regular


expressions
Character Use
[] Square brackets define a list of allowed characters
() Parentheses define a compound element of the regular expression, no matter what it contains
Braces, when they contain one or more figures separated by commas, represent the number of times that the
{}
element preceding the braces may occur (for example p{3,5} corresponds to ppp, pppp or ppppp
- A minus sign between two characters in a list represents an interval (for example [a-d] represents [abcd])
. The dot character represents a unique character
* The asterisk character specifies the indeterminate repetition of the element preceding it
? The question-mark character specifies the possible presence of the element preceding it
| The occurrence of the element located to the left of this operator or of that located to its right (bacon|pig)
^ Used within a list, it means does not contain the following characters

7
E. Some examples of regular expressions

.{3}: string containing 3 characters

A.{4} : string starting with a letter A and with a length of 5 characters ; the last 4 being any character

[a-zA-Z]+: string containing one or more characters included between a and z or A and Z

[^a-zA-Z]+: string which does not contain these ranges of letters

[\+?{}.]: string which contains one of these six characters

[^\+?{}.]: string which does not contain one of these six characters

abc{2}: string containing ab followed by two instances of c ( abcc )

abc{2,}: string containing ab followed by two instances of c or more ( abcc etc..)

[1-2][0-9]{3}: number included between 1000 and 2999

[1-9][0-9]{2}: number included between 100 and 999

(?=.*\w)(?=.*\d)(?=.*\W+).{8,}: password contening 8 alphanumerical characters including a number and a special


character

You might also like