# Restrict typing special characters and spaces inside input

**URL:** <https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702>\
**Category:** Need help\
**Created:** [November 15, 2022, 11:34pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702 "2022-11-15T23:34:44Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![faxtrot117](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/faxtrot117/32/149273_2.png) [@faxtrot117](https://forum.bubble.io/u/faxtrot117)\
**Post date:** [November 15, 2022, 11:34pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/1 "2022-11-15T23:34:44Z")

</div>

Hi all. I have seen many similar threads but never found the solution I need.

All I want is to prevent the user from typing special characters and spaces inside the input field.

Isn’t there an easy way to do this?

I tried “Extract with Regex” and “Find and Replace” but it does not work.

 ![Screenshot_1](https://us1.discourse-cdn.com/bubble/original/3X/7/b/7b8662c4d65f1f2980f195b39b46722331078c75.png)  
 ![Screenshot_2](https://us1.discourse-cdn.com/bubble/original/3X/d/7/d7ffd0e231b5d6fd321ac4e23eb3c61af34484d9.png)

But entering invalid characters and spaces is still allowed. What am I doing wrong? This elementary thing put me in great difficulty.

---

<div class="post-metadata">

**Author:** ![mikeloc](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mikeloc/32/93001_2.png) [@mikeloc](https://forum.bubble.io/u/mikeloc)\
**Post date:** [November 15, 2022, 11:43pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/2 "2022-11-15T23:43:20Z")

</div>

Hi there, @faxtrot117… what you are doing isn’t working because of [this](http://forum.bubble.io/t/how-do-you-limit-special-characters-in-the-input-field-for-usernames/25715/8).

You need to do something like get a count of those characters extracted with Regex, and when the count is greater than 0, show an error message or disable the register button.

Hope this helps.

Best…  
Mike

---

<div class="post-metadata">

**Author:** ![faxtrot117](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/faxtrot117/32/149273_2.png) [@faxtrot117](https://forum.bubble.io/u/faxtrot117)\
**Post date:** [November 15, 2022, 11:46pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/3 "2022-11-15T23:46:55Z")

</div>

Theoretically, I understand you, but how to put it into practice?

It seems to me that I have read all similar posts on this forum, but did not see a specific example that would work.

---

<div class="post-metadata">

**Author:** ![mikeloc](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mikeloc/32/93001_2.png) [@mikeloc](https://forum.bubble.io/u/mikeloc)\
**Post date:** [November 15, 2022, 11:49pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/4 "2022-11-15T23:49:42Z")

</div>

Just to see it work, put a condition on the register button that makes the button not clickable when a condition that includes the expression in your first screenshot plus `:count > 0` is true.

---

<div class="post-metadata">

**Author:** ![faxtrot117](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/faxtrot117/32/149273_2.png) [@faxtrot117](https://forum.bubble.io/u/faxtrot117)\
**Post date:** [November 16, 2022, 12:15pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/5 "2022-11-16T12:15:57Z")

</div>

Thanks for your answer!  
I made it like you told, but still does not work ☹

I put the condition on the register button

 ![1](https://us1.discourse-cdn.com/bubble/original/3X/f/f/ffc6529b0e3e9e194774deb028a6259c33f2312c.png)

But the button is still clickable

![2](https://us1.discourse-cdn.com/bubble/original/3X/2/3/2329eee87f82eba66a3830ab356d30c66b41268f.png)

---

<div class="post-metadata">

**Author:** ![mikeloc](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mikeloc/32/93001_2.png) [@mikeloc](https://forum.bubble.io/u/mikeloc)\
**Post date:** [November 16, 2022, 12:28pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/6 "2022-11-16T12:28:38Z")

</div>

That looks like it should work… are you sure the regex is correct?

---

<div class="post-metadata">

**Author:** ![mikeloc](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mikeloc/32/93001_2.png) [@mikeloc](https://forum.bubble.io/u/mikeloc)\
**Post date:** [November 16, 2022, 12:34pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/7 "2022-11-16T12:34:31Z")

</div>

I just made a quick example with this regex that I got from another thread, and it works as expected for me.

(`|~|!|@|#|$|%|^|&|\*|(|)|+|=|[|{|]|}|||\|’|\<|,|.|\>|?|/|""|;|:|\s)

---

<div class="post-metadata">

**Author:** ![faxtrot117](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/faxtrot117/32/149273_2.png) [@faxtrot117](https://forum.bubble.io/u/faxtrot117)\
**Post date:** [November 16, 2022, 12:35pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/8 "2022-11-16T12:35:01Z")

</div>

I took this regex from [this](http://forum.bubble.io/t/how-do-you-limit-special-characters-in-the-input-field-for-usernames/25715/3) post. This post has several likes, so it seems to be correct.

---

<div class="post-metadata">

**Author:** ![faxtrot117](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/faxtrot117/32/149273_2.png) [@faxtrot117](https://forum.bubble.io/u/faxtrot117)\
**Post date:** [November 16, 2022, 12:35pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/9 "2022-11-16T12:35:48Z")

</div>

Thanks, I’ll try yours regex

---

<div class="post-metadata">

**Author:** ![mikeloc](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mikeloc/32/93001_2.png) [@mikeloc](https://forum.bubble.io/u/mikeloc)\
**Post date:** [November 16, 2022, 12:37pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/10 "2022-11-16T12:37:10Z")

</div>

I got that regex from the same thread that you linked to, so something else is probably going on with your setup. You can try inspecting the button element with the debugger to see if you can get a hint that way.

---

<div class="post-metadata">

**Author:** ![faxtrot117](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/faxtrot117/32/149273_2.png) [@faxtrot117](https://forum.bubble.io/u/faxtrot117)\
**Post date:** [November 16, 2022, 12:39pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/11 "2022-11-16T12:39:04Z")

</div>

Something like this

 ![Screenshot_1](https://us1.discourse-cdn.com/bubble/original/3X/3/1/3187f61af621b32fdb6e93205d4fede026772f13.png)

---

<div class="post-metadata">

**Author:** ![mikeloc](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mikeloc/32/93001_2.png) [@mikeloc](https://forum.bubble.io/u/mikeloc)\
**Post date:** [November 16, 2022, 12:41pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/12 "2022-11-16T12:41:55Z")

</div>

I have this setup in an example that makes a button not visible when a special character is entered in the input field, and it works as expected.

 ![regex](https://us1.discourse-cdn.com/bubble/original/3X/1/e/1eef8702b727c4fcb55708a3155278f8c3f010f1.png)

---

<div class="post-metadata">

**Author:** ![faxtrot117](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/faxtrot117/32/149273_2.png) [@faxtrot117](https://forum.bubble.io/u/faxtrot117)\
**Post date:** [November 16, 2022, 12:43pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/13 "2022-11-16T12:43:31Z")

</div>

thanks, I’ll try this

---

<div class="post-metadata">

**Author:** ![mikeloc](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mikeloc/32/93001_2.png) [@mikeloc](https://forum.bubble.io/u/mikeloc)\
**Post date:** [November 16, 2022, 12:44pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/14 "2022-11-16T12:44:35Z")

</div>

Well, it’s exactly the same as what you are doing except I am making the button not visible instead of not clickable, so I still think there is something else going on with your setup.

---

<div class="post-metadata">

**Author:** ![faxtrot117](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/faxtrot117/32/149273_2.png) [@faxtrot117](https://forum.bubble.io/u/faxtrot117)\
**Post date:** [November 16, 2022, 12:46pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/15 "2022-11-16T12:46:31Z")

</div>

> [@mikeloc](#):
>
> I have this setup in an example that makes a button not visible when a special character is entered in the input field, and it works as expected.

Why is your condition in brackets in this screenshot? I tried to do exactly the same, but I can’t use brackets in the condition field.

---

<div class="post-metadata">

**Author:** ![mikeloc](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mikeloc/32/93001_2.png) [@mikeloc](https://forum.bubble.io/u/mikeloc)\
**Post date:** [November 16, 2022, 12:49pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/16 "2022-11-16T12:49:45Z")

</div>

It’s in brackets because I have the [experimental parentheses](http://forum.bubble.io/t/introducing-experimental-features-including-parentheses/204501) feature enabled, but that shouldn’t matter in this case.

---

<div class="post-metadata">

**Author:** ![faxtrot117](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/faxtrot117/32/149273_2.png) [@faxtrot117](https://forum.bubble.io/u/faxtrot117)\
**Post date:** [November 16, 2022, 12:55pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/17 "2022-11-16T12:55:18Z")

</div>

Okay  
I will just keep looking for solution  
Thank you for your time

---

<div class="post-metadata">

**Author:** ![mikeloc](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mikeloc/32/93001_2.png) [@mikeloc](https://forum.bubble.io/u/mikeloc)\
**Post date:** [November 16, 2022, 12:55pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/18 "2022-11-16T12:55:55Z")

</div>

If you want to share a read-only link to your editor, maybe someone can spot something you are missing.

---

<div class="post-metadata">

**Author:** ![anon38627393](https://avatars.discourse-cdn.com/v4/letter/a/858c86/32.png) [@anon38627393](https://forum.bubble.io/u/anon38627393)\
**Post date:** [November 21, 2022, 2:50pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/19 "2022-11-21T14:50:40Z")

</div>

The issue is because the interpretation of your pattern is only occurring on one event thus far in this thread: on page load.  
Embed your text input in a new group, of type text. Set the initial value of your text input to be the this new parent group’s text. Then on the _text input_, start a workflow of “when input’s value is changed”, then pipe your regex replace into a set-value to the parent group’s text (parent group’s text = input text’s value: regex replace".

This way you fire your regex replace on the event of the user actually typing, instead of just once on page-load. It will write the parent group’s value, which will in-turn reset the input’s value with the replacement.

---

<div class="post-metadata">

**Author:** ![faxtrot117](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/faxtrot117/32/149273_2.png) [@faxtrot117](https://forum.bubble.io/u/faxtrot117)\
**Post date:** [November 21, 2022, 3:06pm UTC](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702/20 "2022-11-21T15:06:13Z")

</div>

Sounds good. Thank you a lot, I will try this.

[Next page](https://forum.bubble.io/t/restrict-typing-special-characters-and-spaces-inside-input/232702.md?page=2)
