HomeGuidesReference
Log In
Reference

Input validation

Forage validates an EBT Element’s input as a customer types. To notify customers of errors, listen for errors on the change event.

Examples

Listen for input changes on a balance check element and display a message if there’s a validation error

balanceElement.on('change', (event) => {
  if (event.error) {
    // show validation error to customer
    setValidationMessage(event.error.message)
  } else {
    // hide validation error
    setValidationMessage('')
  }
})
balanceElement.on('change', (event) => {
  const explainErrorSpan = document.getElementById('explain-error')
  if (event.error) {
    // show validation error to customer
    explainErrorSpan.textContent = event.error.message
  } else {
    // hide validation error
    explainErrorSpan.textContent = ''
  }
})