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.
Comments
0 comments
Please sign in to leave a comment.