Regular Expressions
From Business Process Management, BPM and Workflow Automation Wiki | BizAgi BPMS
<keywords content="keywords"> regular, regular expressions, regular expression, reg. expression, regular exp., reg exp, valid email, email address, e-mial </keywords>
Contents |
Regular Expressions
A regular expression is a special text (with a defined syntax) for identifying a pattern of characters or a particular character. In Bizagi, for Text or Extended Text type fields, there exists the option to use regular expressions to validate the content that is entered. This functionality is not meant to make replacements of the text that is entered, if the text does not satisfy the regular expression the field in the form is left empty. It is found in the Properties option of the render.
Examples
Only Numbers
A person's ID may be created as an attribute of a string type. A restriction says it can only contain numbers so it is necessary to control that a user does not enter characters other than numbers. In this case the regular expression: ^[0-9]*$ can be used.
In the Web Application, if a character different from a number is typed, when the field loses focus it will be cleared (erased):
Otherwise, it is left unchanged:
Only Letters
To validate that only letters (both, lowercase and uppercase) are entered in a text use: ^[a-zA-Z]*$
If only uppercase are allowed, the regular expression to be used is: ^[A-Z]*$
These two last regular expressions would invalidate a text that includes a blank space. If blank spaces are allowed then change the first expression to ^[a-zA-Z\s]*$ and the second to ^[A-Z\s]*$
Another important thing for Spanish-speaking users is that these regular expressions would also invalidate texts that include the letter Ñ (in lowercase or uppercase).
To prevent this use: ^[a-zA-ZñÑ]*$
Only Letters and Numbers
The regular expression: ^[a-zA-Z0-9]*$ will prevent special characters (like:!"#$%&/()=?@) from being entered.
Valid Email Address
To validate that a correct email address is entered in Bizagi, it is not necessary to use a regular expression. This should be done in the Validation option of the field. Click on Validation while standing on the Email attribute in the Forms Designer.
The Field Validation window opens. Type a Description for the validation. In the Condition area select "Email" from the first combo box and in the second, select "is an invalid E-Mail" option.
Finally click on the Save button in the Forms Designer.
In the Web Application, if text that does not represent an email is typed, when the Next button is clicked, the process will not continue and the configured error message will be shown.
If a regular expression has to be used, this is an example of one that works with most email addresses: ^[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4}$
This regular expression will only work for addresses that have a 2 to 4 letters suffix, for example co, com, net, info, etc. Another restriction is that the part before the @ may only contain letters, numbers and some special characters (._%+-)
A great disadvantage of using a regular expression to validate an email address is that, because the field is cleared when it loses focus, if it is not a required field, the user may leave it empty when the Next button in the form is clicked.
- To understand more about regular expressions' syntax refer to this page: http://en.wikipedia.org/wiki/Regular_expression#Syntax
- Another useful link is: http://www.regular-expressions.info
<comments />