Input Validation

Slack modals provide input validation for elements that are contained in input components. Error messages are displayed when the modal is submitted.

While Slack provides some client-side validation in Slack apps, we recommend that you run input validation based on your app's business logic. For example, Slack displays an error message on an empty required field when you try to submit a form.

Required field displays an error

Apex SDK for Slack's field-level validation enables you to handle additional checks on your user input, displaying any errors on form submission.

Specify the data type for an input component that's used to automatically validate the format of the element value entered by the user. If validation fails, an error message is displayed.

To validate the input value, use the type property of the containing input component.

If the textInput does not contain a valid number, user submission is aborted and an error message appears below the input element.

Number field displays an error

Apex SDK for Slack offers a set of types that describe the expected format of an input value based on the user locale in the Salesforce org.

  • currency
  • email
  • number
  • url

The currency locale in the Salesforce org determines if a currency input is valid. Currencies are valid with or without a currency symbol or ISO currency code. The numeric value supports grouping separators and decimal symbols depending on the locale.

For example, $1,025.7 is valid when the currency locale is English (US) and £1,025.7 is valid when the currency locale is English (UK).

To see your org's currency locale, from Setup, click Company Information. On the Company Information page, find the Currency Locale field. The currency local is global and impacts all users on the org.

A valid email follows the pattern username@domain.com or user.name@domain.com.

Here are a few examples.

  • Valid: example@domain.com or example+group@domain.com
  • Invalid: example@domain or example name@domain.com

The user locale determines if a number input is valid. For example, 12,345 is valid when the locale is English. But 1.025,7 is valid only if the locale is German or Dutch.

Here are a few examples based on the English locale.

  • Valid: 1.00, 1,000, or 1,000.00
  • Invalid: 1.2.3

A valid URL includes a protocol followed by the domain name and optional parameters. Unicode domains are not supported.

Supported protocols include http://, https://, ftp://, ftps://, and many others like mailto: and news:. Anchor links are supported.

Here are a few examples.

  • Valid: http://www.salesforce.com or https://example.com?testKey=testValue
  • Invalid: salesforce.com or www.salesforce.com

Using Apex code to validate user input is not yet supported.

Validation using Apex code is subject to Slack's three seconds acknowledgment response. Otherwise, the user receives a connection error in the modal. Dependent field validation is not currently supported if it involves a call to Salesforce.

These field types are not yet supported.

  • Multicurrency
  • Geolocation
  • Phone number
  • Text