# Force uppercase and block spaces in a form field

> A short JavaScript snippet that removes spaces and turns letters into capitals as people type in a text field of a form.

Source: https://tadabase.com/docs/developers/restrict-space-and-force-uppercase-in-a-form  
Status: Verified Nov 17, 2026. Checked against the current product

Codes such as part numbers, license plates or coupon codes are easier to match when they have no spaces and use only capital letters. This snippet cleans a text field of a form while people type: it removes every space and turns letters into capitals.

> **Only need to refuse bad values?:** A form's **Validation Rules** tab can check values when the form is submitted and show your message, with no code. See [Validation rules](https://tadabase.com/docs/workflows/validation-rules). Use this snippet when you want to fix the value as it is typed instead.

## Find the two IDs

| ID | What it looks like | Where to find it |
| --- | --- | --- |
| Component ID | `component_3` | The form component's ID. See [JavaScript callbacks and actions](https://tadabase.com/docs/developers/javascript-callbacks-and-actions). A component on a layout uses `component_layout_` followed by its number. |
| Input ID | `fieldP74QYbjBEm` | `field` followed by the field's ID. Open the page in your live app, right-click the text box and choose **Inspect**: the input's `id` attribute holds it. |

## Add the code

1. **Open the page** In the Page Builder, open the page that holds the form and go to its **JavaScript** tab.
2. **Paste the snippet** Paste the code below and replace `component_3` and `fieldP74QYbjBEm` with your two IDs.
3. **Save and test** Save the page, open it in your live app and type a value with spaces and lowercase letters into the field.

```javascript
// Runs each time the form component is shown.
TB.render('component_3', function (data) {
  var input = jQuery(data.ele || document).find('#fieldP74QYbjBEm');

  // .off() first, so a form that is shown again does not get a second handler.
  input.off('input.uppercase').on('input.uppercase', function () {
    var cleaned = this.value.replace(/\s+/g, '').toUpperCase();
    if (cleaned !== this.value) {
      this.value = cleaned;
      // Tell the form the value changed, so the cleaned value is the one saved.
      jQuery(this).trigger('change');
    }
  });
});

```

- `TB.render` runs your function every time the component is drawn, including after the form reloads, so the field stays covered.
- The pattern `/\s+/g` matches spaces, tabs and line breaks. To keep spaces and only force capitals, remove `.replace(/\s+/g, '')`.
- To clean several fields, repeat the `find(...)` block with each input ID.

## Limits

- The snippet only runs in the browser, on this form. Records created by imports, the API, workflows or other forms are not changed.
- The snippet changes what is typed; it does not check the value on submit. To refuse a value that still has spaces when the form is submitted, add a validation rule as well.
