All Collections
Versions 3.0 and 2.0
Implement
Platform SDK
How can I use Regex in the Platform SDK?
How can I use Regex in the Platform SDK?
Elisa Dinsmore avatar
Written by Elisa Dinsmore
Updated over a week ago

This article is for Flatfile's Portal 3.0 and Workspaces. If you'd like to check out the latest version of the Flatfile Data Exchange Platform, click here!

We do not currently have a unique validation option for Regex, but it can be implemented using the validate field hook. To set this up in your Platform SDK schema, you will want to set your expression as a variable surrounded by forward slashes ( /[regularexpression/) within your validate hook, and then use an if statement to compare the field to the expression using regex.test. Error messages can be set here to inform your user of how to fix the field if it does not pass validation, and you can set the level of the message as well.

Example:

country: TextField({  label: 'Country',  validate: (country:string) => {    constregex= /^[A-Z]{2}$/    if (!regex.test(country)) {      return [newMessage('must be a valid country', 'error', 'validate')]    }  },}),

For more information about our Data Hooks® and how to use them in the Platform SDK, please visit our developer documentation.

Did this answer your question?