Tags

, ,

In the past, I had no idea of Regex – what it is, what it means, what you can do with it. Now that I had to use GREP for my study (using regular expressions for Find/Change in InDesign documents), I found out that using Regex can be less complicated than expected. And because you can benefit from it in your DirectSmile Cross Media campaigns, I would like to share my Regex experience with you.

If you place a text input field on the page, you can enable a validation. There are different types of validation, e.g.: not empty (there must be any input, no matter what), date with specific format or mail address. The latter checks only if there is an @ inside the text input, not more.

Regex1

Let’s have a look at some examples where we could need much more specific validation. OF course, this is just an examply. Once you know the regular expressions, you can use them for any kind of validation.

My colleague Nog wrote more information about how to use Regex in your DirectSmile Cross Media sms configuration here:

http://forum.directsmile.com/forum.directsmile.com/networks/forum/thread-867.html

Example 1
If you create a form that your colleagues can use to request a new e-mail address, you want to be sure that they enter the company e-mail address correctly. It would be great if the validation could not only check if the the e-mail address is anything@anything but anything@yourcompany.com

Therefore you can use the validation type Regex. You will see a new tab:

Regex2

We use this text field to define the input requirements. It should be anything@yourcompany.com
The second part is easy, it should be the fixed text @yourcompany.com
The first part could be any text, so it needs a Regex for that:
.@yourcompany.com

Regex3

Why .@yourcompany.com? Because . means that there must be any character.
That Regex would allow to type peter@yourcompany.com but not peter@yourcompany.de or only @yourcompany.com
Unfortunately it would also allow peter123@yourcompany.com

Example 2
If you want to make sure that your colleagues fill out the form in that way: firstname-lastname@yourcompany.com
You need a Regex that allows anytextanytext@yourcompany.com

Solution:
.\-.@yourcompany.com

Regex4

The . can be any text. The backslash defines that there has to be the following character (in this case the hyphen) and the second . is again any text.
That Regex would allow peter-smith@yourcompany.com but not peter@yourcompany.com or petersmith@yourcompany.com
Unfortunately it would still allow 123-smith@yourcompany.com

Example 3
Now if you know that your company e-mail addresses contain always a-z and definitely nothing else, you could also define that the text before and after the hyphen must be a-z. The Regex could look like this, but I’ll already let you know that this is not enough:

[a-z]\-[a-z]@yourcompany.com

That Regex would allow a-l@yourcompany.com or b-r@yourcompany.com but not peter-smith@yourcompany.com
You see, [a-z] allows a character from a-z, but it allows only one character. To allow more than one, you can simply add a plus. A plus in Regex means that there is one or more of the previous character type.

[a-z]+\-[a-z]+@yourcompany.com

Regex5

This Regex will finally allow only text like peter-smith@yourcompany.com or susan-miller@yourcompany.com but not anything like petersmith@yourcompany.com, 123-smith@yourcompany.com or @yourcompany.com

Finally, I hope I could show you that you can easily learn some regular expressions for your Cross Media campaign validation. Of course the world wide web is full of information about Regex, but most of them seemed to complicated for beginners like me. That’s why I started with wikipedia here, exceptionally, to get an overview of the basix Regex:

http://en.wikipedia.org/wiki/Regular_expression

Advertisements