[Solved] Special characters are not checked and skipped?

I wonder how it is possible in my function, if I enter a special character in the input field username, that this does not give my intended error message but simply skips and executes the else?

I’m scratching my head because it works in my create password input field but not here for a simple username?

Here is the “buggy” code:

Which character causes the condition to be false? Is that character listed in the does contain block?

Can you post a link to your project?

I still don’t get it… tried other things but still the same… not checking the special characters

here is my project: Thunkable

Without this information, it’s really hard to help you.

any character of this: !"#$%&'()*+,-./:;<=>?@^_`{|}~

Mostly I’m testing with the “!”

At least, I just want that a new user needs to create a username with only letters and numbers but don’t special characters

Okay, here’s the problem with your code. I find it confusing to use the not block. I understand why you did but your IF condition says if there is not a symbol, display an error message; if there is a symbol, allow the username.

Your current blocks have added a NOT block when compared to the screenshot you posted above:

I would much rather have an IF condition that says if the string of symbols contains the current letter of the text input, display an error message; ELSE, allow it.

The other problem with your code is that you are running a loop to check each letter but all that matters is the last letter of the username they entered. A loop like that will check each letter but will think #####M is valid while MMMM# is not.

Instead, you need to set a variable to false and then run the loop and change only the value of the variable to true if a symbol is found (and then break out of the loop if you wish to be more efficient). Then after the loop has completed, you check to see if that variable is still false which means the username is valid or is true which means a symbol was found. And then based on that variable value, you display a message to the user.

hmm ok thanks

I just removed the NOT block and having the same issue

but let me try your idea with setting a variable to false or true and then return the value

Thank you for the first tatiang

It works tatiang! So you so much for your thinking and helping.

Here is the solution:

As you said, working with boolean true and false makes it to work

Topic can be closed

1 Like

FYI, topics can be marked as solved by clicking on the check mark below the reponse that solves this issue.

1 Like

You’re welcome!

I have something for you to consider next time you need to check a username or password for valid characters. The way you are doing it is fine but it’s time-consuming to set up.

Here’s another method that uses fewer blocks:

Project link (see the first screen): Thunkable

1 Like