Riddle supports REGEX (regular expressions) with our online quiz maker. We added this tool to give you total control around how your quiz lead data is formatted – it’s especially useful for tricky strings like international phone numbers.

Using a lead capture form before you show the results to a quiz, personality test or poll is a great way to get leads and grow your email list.

Why use REGEX for quiz lead generation?

Sometimes you need your users’ quiz data is in the right format for processing. For every form field, you can enable REGEX validation by enabling the advanced validation options in the form field settings.

REGEX Form field validation options

Here are some sample use cases:

  • Ensure a phone number is in the right format (e.g. ###-###-##### for US contacts)
  • Make sure a street address contains a number
  • Make sure an entry has a minimum number of characters
  • For certain special characters
  • Match elements of a URL (if you only want to limit entries to people with .edu domains, for example)

For all these purposes, here comes a super powerful new form field in the Riddle quiz maker lead generation form builder: REGEX fields (short for Regular Expressions)

To understand REGEX, check out this example with explanations on how to check if a form field entry is a valid U.S. ZIP Code:

The Regular Expression for a valid US ZIP code is: /^\d{5}(?:[-\s]\d{4})?$/

This regex will match any US zip code that is in one of the following formats:

  • Five digits (e.g. 90210)
  • Nine digits with a hyphen or space between the fifth and sixth digits (e.g. 90210-1234 or 90210 1234)

The regex uses the following elements:

  • ^ matches the start of the string
  • \d matches any digit (0-9)
  • {5} matches the preceding element (a digit) exactly five times
  • (?:) is a non-capturing group that allows multiple regex elements to be combined
  • [-\s] matches either a hyphen or space character
  • ? makes the preceding element (the non-capturing group) optional, allowing the regex to match either five or nine digits
  • $ matches the end of the string

Overall, this regex will match any valid US zip code, including both five-digit and nine-digit codes with a hyphen or space between the fifth and sixth digits.

We should tell you upfront – REGEX is powerful, but more than a little complex. Don’t fret – we’re here to help out! 

Step by step instructions

Right, for everyone else, get a cup of coffee and read on.

With REGEX you can make sure that the data entered into a form field follows a very specific formatting rule.

  • For example, imagine your database requires all phone numbers to be in the format (area code)-3digits-4digits like (402)-123-3434:
  • You can use REGEX to accept any slight variation of that – such as 1 (402).123.3434.
  • Define the required format – your readers won’t be able to submit the form until their phone number matches that format.
  • All the data in your database will be nice and consistent. 

The regular expression you need to enter to achieve that result is:

((\d)\D)?(\(?(\d\d\d)\)?)?\D(\d\d\d)\D(\d\d\d\d)

Sure – not very intuitive, but once you get the hang of REGEX, you can do one heck of a lot.

Now, none of us here at Riddle have all these regular expressions memorized – but there are some really good websites to help you with this.

My current favorite: https://www.regextester.com/

  • They have a great list of top regular expressions such as “Match dates”, “URL”, “Check if a string contains a number”.
  • Plus they include both a cheat sheet and a tool so you can test your expressions before you add them to your Riddle quiz.

For a longer introduction, we recommend this Medium Post to read if you are brand new to Regex.

In Riddle 1.0 – REGEX is a separate field type

Just stop reading right here and log in to Riddle’s quiz maker – then add the new form field to your lead forms.

regex

And of course, you can always ask us at via support chat or hello@riddle.com – as customer service geeks, we’re super fast at responding.

Leave a Comment