Accept values as. $ [] firebase

Friends, I would like a solution for a problem I have.

In my application I have the id as a unique requirement on each device, but when I upload the id of a device that contains characters such as “.” or “$” or “-” or “[” etc … it shows me an error, understanding that it is not allowed to upload these values to the database and I can not upload them.

example: a cell phone has the ID: and when registering it in my firebase, it does not allow me those values. How can I make it allow me to upload this type of values to the database?

The only solution to this would be to either set it a value to a key OR use you can replace the symbols with blank text and then do the same in the back-end so that it will equal the database ID.

String id = "";
String comparisonId = id.replace(".", "").replace("-", "").replace("$", "");
/** You can replace more symbols by appending .replace("symbol goes here", "") **/
String firebaseId = comparisonId;

Understand the example? You wouldn’t use the id variable to compare and store, instead you would use the comparisonId variable. The replace block can be found in the text section of Kodular.

1 Like

I understand the friend example, but what happens when I want the user to login, I use the ID of the devices as registration / login identity in my application.

Example: User ID: “”, but when uploading to firebase it would be: “FGA45 sg 1 8”.
When making the comparison of whether the user is registered or not in the database, then his ID will not be the same as that of the firebase, but actually if he is registered. How can I fix it?

You did not understand the example. Let me show you something…

String id = "";
String comparisonId = id.replace(".", "").replace("-", "");
/** comparisonId would equal "FGA45sg18" **/
String firebaseId = comparisonId;

The comparisonId would equal “FGA45sg18” since it is replacing the illegal characters with a blank character. If I were to do .replace("-", " ") then yes it would leave spaces. Try it on the companion first and see the result.

1 Like

If it works, it lets me save the ID value without the invalid characters. OK perfect
the problem is that my users when they click the login button I check if the ID of their device is in the list of IDs in the database (firebase), but it will take me as not in the firebase for that its real ID has the invalid characters.

How do i put it the same in the database? because that way you could make the comparison correctly.

Do you understand what I want to tell you?

OK, I am understanding, you are not understanding.

I’m telling you to use the same blocks for Firebase as you do to compare the device ID when the user signs in.

blocks (11)

You would store the DeviceID variable in Firebase as well. Don’t forget to change the text block with “” in it to the block you’d like to use to get the DeviceID.

Do what @hammerhai said: remove the special characters , during login, and compare It with the tag that also removed the special characters.

1 Like

Ok, so I hadn’t understood your example very well, hahahaha thank you friend for having patience with me.

friend another question. How do I add more invalid characters (with a list) (could you show me with blocks please)? example:. -% $ "! {},; etc …

and what if there is an ID that does not contain these characters? will it give error or ignore it?

1 Like

Yes if the character does not exist you will be fine. Below I have shown that you can create a procedure that will take care of it. Of course to add more symbols, you can just extend the list.

blocks (12)

blocks (13)

As before, you’d replace the input in the second picture with the DeviceID variable.


So you have to send the ID_device to the database, would you put the block “call RemoveIIIgalCharacters”?


blocks (15)

1 Like

¡Thanks friend!

1 Like

You’re welcome!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.