Appearance
Writing Actions
Input Validation
Forge I/O methods include basic validation by default:
io.input.emailchecks for a valid email.io.input.numberensures a valid number is provided.
Custom Validation
To add custom validation, chain the validate method to an I/O method or io.group and pass in a custom function which processes the input and returns
- return
nullif valid - return
stringmessage if invalid
Tip: Validation functions run on your infrastructure alongside the action logic, so you can access any other code as needed.
INFO
Validation functions can be asynchronous.
Example Usage
ts
await io
.group({
name: io.input.text("Name"),
email: io.input.text("Password").validate((email) => {
if (isPreviousPassword) return "Previously used passwords are not allowed."
}),
})
.validate((data) => {
if (isInvalidCredentials) return "Invalid credentials."
});python
await io.group(
io.input.text("Username"),
io.input.text("Password").validate(
lambda s: "Previously used passwords are not allowed."
if is_previous_password
else None
),
).validate(
lambda data: "Invalid credentials"
if is_invalid_credentials
else None
)