Start a conversation

Check if a text field contains any numbers

When using a text field, you can use the following template to check whether the field contains any numbers and display a message of your choice. 

Create a calculation field in the study form using the calculation field example below - remeber to replace 'variable_name' with the variable name for the text field. You can also update the messages shown to display the wording you prefer.

if ((/\d/).test('{variable_name}')) { 
    "The entered value contains numbers."
} else {
    "The entered value does not contain any numbers."

Test the calculation in the calculation helper.

Choose files or drag and drop files
Was this article helpful?
  1. Castor Support Team

  2. Posted
  3. Updated