Validate Unique Username entered by user

Hello,

my users are loging in and at the moment i give them a unique username based on their email (every character before the @) + the 3 first characters from the Unique identifier

I’d like to offer them the possibility the change their username but i’m struggling to see how to prevent them from entering let’s say JOHN if JOHN already exists as a username for another user…

Any clue? Much much appreciated thank you

That “Edit” option makes it trickier I think.

To check if a value has already been entered in the database, my go-to method is:

  • Create a user-specific column.
  • Make a text entry that write to that column.
  • Make a relation that matches the value in that column to the field I want to check if there’s a duplicate.
  • Allow the value to be entered if there’s no match and vice versa.

I don’t think we can do that inside an Edit option though, is it the same as a Form?

thank you // how would you do this last step?

In my case, it was a booking app so it’s a completely new entry. I show them a button that links to a form and capture the entered value via a “Column”.

Never tried it with Edit option though, so I’m not sure if it works.

Hello @Raph,

I currently have a similar need to validate a user entry with an arbitrary restriction such as duplication. What you could do is do the validation within the spreadsheet and once validated let the user “push” the validated username to the username field.

Unfortunately this would generally rule out using a form, as form values are not written to the spreadsheet until submitted and only write to new rows. However, what you could do is have a 2 step process:

  1. User opens Change Username Page and is presented with a “Validate New Username” form button
    • User clicks the button and the form opens. The user enters their desired username into the only text field and hits submit
    • Their New Username is then logged in the “Username Request” sheet
    • An Excel formula then populates a few fields in the users ownered row (Latest New Name, Valid status)
    • User is automatically returned to Change Username Page (normal for forms)
    • Seconds later a component appears with the results of their validation a yes or a no and their chosen name
    • If yes, another new field will also be available: a choice component with only one possible value: the recently validated name (visibility based on the valid status)
  2. The user now clicks the choice component and selects their validated name, which moves the validated name into the name column

Let me know if you would like more details as I have built and tested the above.

Good luck!

3 Likes

Would this method encounter a lag when you have to submit it back to the Sheets though? If you are using a form to validate it, then I would rather do a relation in that same “Validation” sheet as you have stated, to know if it matches an existing record or not. I think pushing it back to the Sheets is not ideal.

Furthermore, I think it will eat up a lot of rows for the validation and free users won’t like that. Kudos to the idea for the choice component.

2 Likes

Hi @ThinhDinh,

  • The reason I pushed it back to the sheet for validation is that it offers more options. You can do any sort of validation you like.
  • The delay is there of course, anything that goes back to the sheet will have it, but its maybe 2sec, not too bad
  • There are no extra rows used for validation, only for the request submission, and if you are familiar with AppScripts, you could arguably delete the top X number of rows anytime the number of rows reaches some threshold. Also the form ensures that the value, once validated, cannot be changed by the user. This ensures the validation remains true.

The issue is that at any time, if the user is free to enter a value in a free text field, you cannot validate it. Using a pre validated value that is simply selected from a list, ensures the value is valid.

I will admit its not a perfect solution, but it is functional and fairly straight forward.

Thanks for the feedback.

4 Likes

thanks, perfect workaround.

1 Like

Great, glad it was clear enough for you.

Let me know if you need anything else!

1 Like

I think that is achievable with a user-specific column. Using your same method above, it would go like this:

  • User enters their new name using that user-specific entry.
  • A relation validates if that entry is not a duplication of any existing entries.
  • If the relation is empty, then show the choice component to let the user change it, with the only value being the value in the user-specific column. Otherwise don’t show the choice component and show a text that the name is not available.

In my experience, pushing it back to the sheets require more than 2 seconds to bring back the value to the Glide editor and then sync it to the device of the user, so many of us here have always tried to find some ways to do it inside the Editor instead, lagging troubleshoot is a concerned issue we have discussed many times here.

All in all, nice workaround using the Sheets, and if Raph wants to try the steps I listed in this comment, feel free to do so and let us know if you succeed.

Thank you all :smile:

5 Likes

If it’s possible I agree it could be quicker, however I also like to camel case their name and in general if this is to be used for any complex validation, the editor will likely not suffice. Though if duplication is the only criteria and things like first letter capitalisation are not required, then keeping it in the editor may also do the trick!

1 Like

I agree with that, if we need further adjustments on the value, like what you say, camel case the name then we must bring it back to the Sheets.

It also brings me to the question that whether my relation goes the way of exact match or not (i.e Camel is not the same as cAmEl and won’t bring back a relation value ).

1 Like

To me for a function that will happen seldomly a small lag to gain the flexibility of sheets is an easy concession to make.

1 Like

I’ll try this one too and let you know, thanks !

1 Like

Hi, I’m struggling with exactly this right now! :slight_smile: - I have such a relation column set up and it works fine if I directly enter the value in the glide table. But, naturally that’s not how the app will work - I want my ‘primary’ user to be able to add new (secondary) users - is there any way that I can assign the new user’s ID to a temporary variable? I have a column for the temporary variable which what the relationship checks the list of user IDs against. If I use the action ‘set value’ for some reason the value from the form isn’t getting captured in the table at all… what am I doing wrong?

If this helps, this is my form:
clunk
I thought I’d use the clunky manual check button to force a check that the ID is unique before proceeding to fill the whole form. But set column value > this row isn’t adding the value to the admin user’s column.

And, the second weird thing is that while my user ID column is user-specific, I can apparently still have a duplicate entry!


Why is this possible?

image

Is this a native form? The method I mentioned only works with custom forms.

1 Like

Er, sorry, I’m not sure - I called it using “show form screen” from an Add button?

Yes, that’s what I refer to as “native form”.

Please read the “custom form” thread I linked above.

ohhh! sorry sorry, thanks a ton!

1 Like

Also, you may be misunderstanding user specific columns. They don’t ensure that every value in the column is unique. What they do is hold a value uniquely, for each user that’s signed in. You see numbers in that column now, but if a different user signed in, then that entire ID column would be empty.

The purpose of a user specific column is so that multiple users can store a value in one single cell that’s unique to them. Nobody else will see what they entered.

1 Like