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.

  • Verified Nov 17, 2026
  • Classic builder

On this page
  1. Find the two IDs
  2. Add the code
  3. Limits

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.

Find the two IDs #

IDWhat it looks likeWhere to find it
Component IDcomponent_3The form component's ID. See JavaScript callbacks and actions. A component on a layout uses component_layout_ followed by its number.
Input IDfieldP74QYbjBEmfield 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.

Was this page helpful?

Something wrong or missing on this page? Tell us.