# Validation rules to eliminate blank spaces is short text field

**URL:** <https://forums.knack.com/t/validation-rules-to-eliminate-blank-spaces-is-short-text-field/17569>\
**Category:** Get Answers\
**Created:** [July 15, 2024, 12:39pm UTC](https://forums.knack.com/t/validation-rules-to-eliminate-blank-spaces-is-short-text-field/17569 "2024-07-15T12:39:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bruno1](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@Bruno1](https://forums.knack.com/u/Bruno1)\
**Post date:** [July 15, 2024, 12:39pm UTC](https://forums.knack.com/t/validation-rules-to-eliminate-blank-spaces-is-short-text-field/17569/1 "2024-07-15T12:39:12Z")

</div>

Hello!

I have this issue with a required, short-text field. I would like my users to insert data without blank spaces, however they tend not to go with this…

I need the input to be ABC123, however there are ABC 123, or ABC1 23 and even ABC123 (multiple blank spaces in the end).

I have tried a validation rule to reject and notify users of this issue. I used FIELD CONTAINS [empty space] however this is blocking ALL input in the field, even the ones that have no blank spaces.

Any suggestions?

Thanks a lot,

Bruno

---

<div class="post-metadata">

**Author:** ![CSWinnall](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/cswinnall/32/3631_2.png) [@CSWinnall](https://forums.knack.com/u/CSWinnall)\
**Post date:** [July 15, 2024, 3:25pm UTC](https://forums.knack.com/t/validation-rules-to-eliminate-blank-spaces-is-short-text-field/17569/2 "2024-07-15T15:25:32Z")

</div>

Hi Bruno

Please see this:

> [@Forbid whitespace character in account table](https://forums.knack.com/t/forbid-whitespace-character-in-account-table/15135/3):
>
> Ahoy! @Francois I also tried field validation rules with regex and didn’t have much luck! Below is the JavaScript method. When a white space is added to field\_xx, it will automatically erase it on keyup. Hope that helps. $(document).on('knack-view-render.any', function(event, scene) { // Prevent whitespace input in a text field with key 'field\_xx $('#field\_xx').on('input', function() { this.value = this.value.replace(/\s/g, ''); }); });

Craig

---

<div class="post-metadata">

**Author:** ![Bruno1](https://avatars.discourse-cdn.com/v4/letter/b/b2d939/32.png) [@Bruno1](https://forums.knack.com/u/Bruno1)\
**Post date:** [July 15, 2024, 4:07pm UTC](https://forums.knack.com/t/validation-rules-to-eliminate-blank-spaces-is-short-text-field/17569/3 "2024-07-15T16:07:35Z")

</div>

This is perfect Craig, works perfectly, thanks a lot!

Bruno
