Skip to content
NatashkaX edited this page Aug 21, 2017 · 15 revisions

In the Forms Node, you can set validation for the form. If the user submits the form and does not pass validation, then the validation alert will be displayed.

The below screenshot shows validation for a form field named 'email_address'

The critical point is that the 'validation' column needs to be an R code conditional, and the conditional needs to validate as TRUE in order for the form to be successfully validated:

i.e. behind the scenes it does: if (condition) { continue with test } else { show validation error }

Note that in the conditional you can use the name of any form fields you have created in the form. In the case above we're using the "email_address" form field and we're validating whether it's empty or not.

If the form is not successfully validated then the 'validation alert' will be displayed in an error box. Multiple validation alerts could be displayed if the user has failed validation on multiple fields.

Q. How do I do better e-mail address validation?

Actually the e-mail address example above is very simple; it only checks if the user has entered anything at all, so the user could still enter 'test' as their e-mail address. But since you can put any conditional statement in the 'validation' field, you can use any R function you want in there. Here's some more advanced R e-mail address validation using grep:

grepl("\\<[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}\\>", as.character(email_address), ignore.case=TRUE)

If you copy the code above into the 'validation' field then basically it'll check that the email_address form field contains something@something.something

Q. How do I do better age verification?

The best method is get the user to enter their DoB in three drop-down lists, i.e. one for date, month, year of birth. If you're simply getting a user to complete a blank space with their age, then this will help:

grepl("^[0-9]*$", as.character(age), ignore.case=TRUE)

It ensures that there are only numbers in the box. It allows a blank response though. If you need the user to enter at least one number then change the * to a +

It is shamelessly stolen from this StackOverflow question.

Clone this wiki locally