How do I only accept valid data in my form fields?

Created by Nick Duell, Modified on Thu, 12 Sep at 12:46 PM by Nick Duell

Validate Logic helps you control when and how fields in your form need to be filled out. By default, all fields are required, but with Validate Logic, you can add conditions, making fields optional or ensuring they meet certain requirements.

Validate Logic allows you to control when a field in your form needs to be filled out a certain way — not just that they have a value, but that the value matches certain rules (logic) that you have added.

Example

Imagine you have a student ID number field on a staff form. You might want to make sure this field only accepts a certain number of digits, like exactly 6 characters for a valid ID. Or, for an expense report field, you may want to ensure that the number entered doesn’t exceed a specific limit, like $5,000.

The Easiest Way: Use Droplet AI

The easiest way to configure Validate Logic on your form fields is to use Droplet AI to write an expression for you!


Here's how:


1

In the Form Editor, select a component and click Validate Logic from the properties panel.

2

In the top pink bar, type the validation conditions you would like to apply to this field in plain wording, for example: "must be less than $200."

3

Press enter and await a response from Droplet AI.  Accept its recommendation by clicking the Accept icon or by pressing Done.

4

Test your field to ensure it is adhering to the new Validate Logic you have added to it by Previewing/Debugging the form.


Droplet AI will be using some functions to write Validate Logic for you.  If you'd like to know more about what it is writing or how you can write your own logic, keep reading about helper functions below.


Write Validate Logic with Helper Functions

Droplet has a variety of shortcuts (called Helper Functions) to make writing Validate Logic easier.  Think of them like Google Sheets or Excel functions.


Pro Tip!
If you want to refer to the value of the field you’re adding validation to, you can either use the field’s component ID or simply use the word ‘value’ to refer to its own value.


equals(value, comparison)
Checks if two values match exactly

You can also use:
value === comparison
Example Use
equals(employeeSignature, employeeName)
If this Validate Logic is on the Employee Signature field, it would force the user to sign their name exactly as typed in the Employee Name field. Handy!
notEquals(value, comparison)
Checks if two values do not match exactly

You can also use:
value !== comparison
Example Use
notEquals(parentEmail, studentEmail)
Adding this Validate Logic to either the Parent Email or Student Email fields would ensure that the two email addresses must be different.
withinRange(value, min, max)
Verifies that a value falls between a minimum and maximum range
Example Use
withinRange(studentAge, 5, 18)
This checks that the age entered is appropriate for the grade levels allowed in your district.
isGreaterThan(value, comparison)
Confirms that one number is greater than another

You can also use:
value > comparison
Example Use
isGreaterThan(fundingAmount, 1000)
Let's say you want to ensure that a funding request field only accepts amounts over $1,000. This guarantees that the requested amount meets your minimum threshold.
IsGreaterThanOrEqualTo(value, comparison)
Confirms that one number is greater than or equal to another

You can also use:
value >= comparison
Example Use
isGreaterThanOrEqualTo(qty, 10)
Suppose you want to make sure an order quantity field allows a minimum order of at least 10 units. This ensures that users can’t submit an order for fewer than the minimum allowed quantity.
isLessThan(value, comparison)
Ensures that one number is smaller than another

You can also use:
value < comparison
Example Use
isLessThan(vacationDays, 30)
Maybe you want to limit the number of vacation days an employee can request to under 30. This makes sure the user doesn’t request more than the allowed days off.
isLessThanOrEqualTo(value, comparison)
The value must be less than or equal to a specific number

You can also use:
value <= comparison
Example Use
isLessThanOrEqualTo(expenseTotal, 5000)
Perhaps you want to set a cap on an expense field so it cannot exceed $5,000. This Validate Logic makes sure the submitted expense stays within budget limits.
and(condition 1, condition 2)
Ensures that all conditions are true

You can also use:
condition 1 && condition 2
Example Use
and(checklistCompleted, completionDateEntered)
In this example, both the checklist and completion date must be filled in before the submission can proceed.
or(condition 1, condition 2)
Allows for at least one condition to be true

You can also use:
condition 1 || condition 2
Example Use
or(phoneNumberProvided, emailProvided)
You want to give users the option to enter either a contact phone number or an email address. This flexibility allows the form to accept at least a phone number or email for contact purposes, but doesn't force them to provide both.
includes([list], value)
Checks if a value is part of a specific list

You can also use:
[list].includes(value)
Example Use
includes(['UT','NY','MA'], value)
You want to make sure the selected state is one of the allowed options for your district. This ensures that users only choose from the allowed states when filling out the form.

Of course, we'd recommend just using a dropdown, radio button, or checkbox to narrow choices like this!

To Use Within Other Helper Functions

isOptional()
Marks the field as not required
Note!
To make a field optional, just turn off the Required switch in the field’s properties panel. However, if you need to make a field optional based on certain conditions, you can use this helper function.
Example Use
equals(nextAction, 'Approve') ? value : isOptional()
Tricky one: this is called a ternary statement.  If you're familiar with IF statements in spreadsheets, same thing!

The first test is "Is Next Action equal to Approve?"  If so, this will require a value in the field.  Otherwise, it will make it optional.
value.length
This tells you how many characters are in a value.  For lists, it will tell you how many items are in the list.
Example Use
equals(value.length, 6)
This uses two things: the equals function (see above) and the .length method. This logic ensures that the submitter enters a value that is exactly 6 characters long in the field.

Great for ID numbers and account codes!
toCurrency(value)
Converts a number into a formatted currency string, like turning 5 into $5.00

This is especially helpful when used with other helper functions, if you need to format a number as currency.
Example Use
equals(toCurrency(value), toCurrency(total))
This is using two functions: the equals function (see above) and the toCurrency function.  This is forcing both the field value and the total value into currency format before ensuring that they are equal to each other.
fromCurrency(value)
Converts a currency string back to a number, like turning $5.00 into 5

This is especially helpful when used with other helper functions, if you need to format a currency value as a number first.
Example Use
lessThan(value, fromCurrency(budget))
This is using two functions: the lessThan function (see above) and the fromCurrency function.  This is forcing the budget value into number format before ensuring that the current field value is less than the budget value.
Pro Tip!
We recommend adding a tooltip or hint to fields with Validate Logic to help the user understand what they need to provide in order to successfully submit.


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article