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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -