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?
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.
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.