Good way to replace invalid characters in firebase keys? -
my use case saving user's info. when try save data firebase using user's email address key, firebase throws following error:
error: invalid key e@e.ee (cannot contain
.$[]#)
so, apparently, cannot index user info email. best practice replace .?
i've had success changing . - won't cut since email's have -s in address.
currently, i'm using
var cleanemail = email.replace('.','`'); but there going conflicts down line this.
in email address, replace dot . comma ,. pattern best practice.
the comma , not allowable character in email addresses is allowable in firebase key. symmetrically, dot . is allowable character in email addresses not allowable in firebase key. direct substitution solve problem. can index email addresses without having loop on anything.
you have issue. in code:
var cleanemail = email.replace('.',','); will replace first dot . email addresses can have multiple dots. replace dot instances, should use regular expression instead. follows:
var cleanemail = email.replace(/\./g, ',');
Comments
Post a Comment