Skip to main content

How to write your regular expressions ?

Elsa Fernandes avatar
Written by Elsa Fernandes
Updated over 2 years ago

Regular expressions are a technical tool that allows you to control the format of data entered in form fields (for example, telephone number or email). They give great possibilities of control but must be written with great care.

They are not a substitute for data validation, but can help prevent the submission of unusable information.

When setting up a form, it is now possible to add a regular expression on the fields in order to force a precise format by allowing only certain characters or by limiting the number of characters available.

Here are some examples. These are fully adaptable to the different needs according to the fields :

Phone numbers :

Test of a French mobile number (06/07/+336/+337/00336/00337) taking into account several types of codes.

^(\+33|0033|0)(6|7)[0-9]{8}$


You can of course adapt this regular expression for other countries (like Belgium for example with +32/0032)

^(\+32|0032|0)[0-9]{8}$


Test of a French telephone number of 10 characters without international dialing codes.

^(0)([1-9])[0-9]{8}$

Emails :

Testing a valid email with google alias (+). The Google alias allows users to use multiple email addresses that are redirected to the same unique address (e.g. rjoan@cassiop.com and rjoan+1@cassiop.com)

^([a-zA-Z0-9\.\+]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})$

Test of a valid email WITHOUT google alias (+)

^([a-zA-Z0-9\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})$

Test an email by forcing a domain (google.com OR google.fr in this case)

^([a-zA-Z0-9\.]+)@(google.com|google.fr)$

Free text :

Test a text of at least 5 characters (A-Z 0-9) without special characters

^([a-zA-Z0-9\.]){5,}$		

Test a text of 5 characters (A-Z 0-9) WITH SPECIAL CHARACTERS allowed

^([a-zA-Z0-9àáâãäåçèéêëìíîïðòóôõöùúûüýÿ\.]){5}$		

Fixed text test. This regular expression will force the user to fill in a specific text: "TOTAL" or "total" in the following example

^(TOTAL|total)$		

Test of a text starting with ABC and followed by numbers. The "ABC" text is fully editable to suit your needs

^ABC-([0-9])+$

Test a text starting with 123 and followed by letters

^123-([a-zA-Z])+$	

Dates :

Simple test of a date of birth in DD/MM/YYYY format that you can use in a free field

^(0?\d|[12]\d|3[01])\/(0?\d|1[012])\/((?:19|20)\d{2})$	

If you need help writing your regular expressions, we invite you to contact Kimple support or your project manager

Did this answer your question?