The apps cannot insert any data to the database while this line of code makes error to the apps.
ref.child(uid).orderByChild(\"username\").equalTo(validateName)
As your error said, Firebase Database paths must not contain '.', '#', '$', '[', or ']'
. This means that Firebase does not allow you use in the key symbols those symbols. Because of that, you need to econde the email address like this:
name@email.com -> name@email,com
To achieve this, i recomand you using the following methods:
static String encodeUserEmail(String userEmail) {
return userEmail.replace(".", ",");
}
static String decodeUserEmail(String userEmail) {
return userEmail.replace(",", ".");
}
Now currently my code will be like this so where to change that to exists?
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot c : dataSnapshot.getChildren()){
String vun = c.child("username").getValue().toString();
if (vun.equalsIgnoreCase(usnm)){
Toast.makeText(Register.this, "Username Taken. Please try another one.", LENGTH_SHORT).show();
return;
}
}//end of for loop
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});// end of addvalue