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
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 #
| ID | What it looks like | Where to find it |
|---|---|---|
| Component ID | component_3 | The form component's ID. See 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 #
- Open the page In the Page Builder, open the page that holds the form and go to its JavaScript tab.
- Paste the snippet Paste the code below and replace
component_3andfieldP74QYbjBEmwith your two IDs. - Save and test Save the page, open it in your live app and type a value with spaces and lowercase letters into the field.
// 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.renderruns your function every time the component is drawn, including after the form reloads, so the field stays covered.- The pattern
/\s+/gmatches 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.