Forum Academy Marketplace Showcase Pricing Features

Username limitiation?

For anyone that allows users to create usernames on their app, what sort of limitations do you add to the logic?

For example, I require minimum 4 characters, at least one letter, and must be unique.

Lately I have noticed users are signing up with spaces or symbols.

I would look up some username standards to generate a regular expression and use that to validate usernames. I would omit things like spaces and symbols in the event I want to use the username as a vanity URL for the user.

Any ideas on how to eliminate symbols?

Can simply make the workflow condition = username input doesn’t contain symbols. However, not sure if there is any logic in bubble to look for symbol characters.

Just use a regular expression to limit the valid usernames. Anything that doesn’t conform to the regular expression shouldn’t pass. You can compare the original text against the text passed through the regular expression. If they are the same, you can store that username in the database; otherwise, you know they used an invalid character. I don’t have experience using regular expressions on Bubble, but it looks like others in the forum have.

Yeah that part is easy and already setup for all other limitations. Just not sure what in Bubble is available to define if an expression has a symbol in it.

Are you permitting the usage of symbols? If not, just let the regex be the alphanumeric characters, so symbols won’t be captured.

Doesn’t the regex just replace characters?

I’m looking for a way to validate if an input has symbols.

My input is set to text.
I have already created a validation for a minimum amount of characters. To do this, I simply set a condition that says, input’s character :count > X.

Is there a way to validate if the input has a symbol or not. For example? condition = input’s character contains symbol. I’m not sure if Bubble has a way to check for a symbol.

Maybe there is a way to check for alphanumerical?

If it does replace characters, then you can compare the input and output. If they are the same or not, depending on how you implement it, you can use that to validate. For example, if the regex allows only certain characters to pass, and the input and output are the same, you know that the input only uses valid characters. In the inverse of that, where the valid characters are removed, if the output is empty, then the input was valid.

You can use this method to check for the existence of a symbol as well, but not for the inclusion of s specific symbol unless you make the regex very granular.

I think I understand what you mean now. I’ve never used the Regex so I’ll have to do some research and experimenting. Thanks

@anon94914631, do you mind sharing what you did to remove spaces from the username?

Thanks @anon94914631, I will tackle this problem shortly and will report back progress. Thanks for sharing!

That’s great! What’d you find?

I had the same problem.

This is my method. It only allows usernames that have numbers and letters.

I found a solution.

  1. have an input for username
  2. have a button to save/register the username (that starts the workflow for registering the username)
  3. set a condition to the button
    input for username’s value:extract with regex PASTE THIS REGEX CODE [a-zA-Z0-9] doesn’t contain input for username’s value and input for username’s value is not empty
    condition should be this element isn’t clickable and the box should be checked for this condition

so in total the condition FOR THE BUTTON should read:
input for username’s value:extract with regex doesn’t contain input for username’s value and input for username’s value is not empty

If the button isn’t clickable, then the workflow won’t start. If the workflow won’t start, then the user can’t register that username.

You could also have text that uses this very same condition that appears that tells the user why they can’t click.

If you want to allow some characters, after 0-9, just add characters you want. So you can add _ or $ or . or all three in a row but make sure it fits within the brackets [ ] I dont know why you would want spaces for a username.

ex: [a-zA-Z0-9$] would allow $ in addition to letters and numbers.

2 Likes

Not sure what you mean.

I think my method just searches to make sure that the username only contains the characters you put in the brackets of the regex. So the one I used allows any letter, any number, and I included an example about adding characters at the end if you want to allow a certain character.

I dont think there is an order to where you put them in the username or anything about being consecutive.

Test it out and see if it works for your app. Sometimes its about putting two solutions together and don’t worry, eventually you’ll get it right.

By the way, I would have a separate field called display name if you want spaces. So a user can be smithy99 and he can have a display name like John Smith, just to identify himself better.

for what its worth…rather then remove spaces i’ve taken the approach to inform the user if their chosen username does not meet the criteria ive set… in my situation…spaces and special characters will not work as i’m reading the URL. I have two inputs and the second uses regex to simply detect special characters and spaces and based on character count perform action regex (\|~|!|@|#|$|%|^|&|*|(|)|+|=|[|{|]|}|||\|’|<|,|.|>|?|/|"|;|:|\£|_|\s)`

To the point about emoji…i’d not considered this…so @aphz88 approachwould be a good approach…i’ve tried to optimise it from a UX perspective…

So here is what i’ve come up with:

  1. Create your ‘User name input’ Give it an ID
  2. Create a message or some other form of warning indicator…Toast alert blah blah… lets say a simple text box with “Whatever you want message”
  3. Grab the ‘Instant Text’ Plugin from @Airdev
  4. The instant text element should refer to the ‘User Name Input’ ID
    6 You condition for the show msg alert or Toast Alert Extract with Regex [^A-Za-z0-9]+
    ggg

Because the Instant Text Plug fires in real-time you user gets the message / alert and you can of course disable etc…

1 Like

Hi there @aphz88 - thanks for this proposed solution. I understand the logic but am having a hard time implementing it. Would you be able to add some more detail?

I have a text input for username. If the username input contains special characters, or any spaces, I want to show them notification that we don’t allow special characters or spaces.

Much appreciate if you could detail how to execute your solution. Thank you.