Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Disallow or replace certain characters in string with Firebase Realtime Database Security Rules?

Is it possible to disallow or replace certain characters in string with Firebase Realtime Database Security Rules?

For example disallow the "<" character?

Or replace the "<" with ">" character?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes, this is definitely possible with Firebase Realtime Database security rules.

You can use the .validate rule to specify a regex pattern that data must match. For your specific examples, you could do:

Disallow <: .validate(!newData.hasChildren() && !newData.val().matches('<'))
Replace < with >: .validate(!newData.hasChildren() && newData.val().replace('<', '>').matches('[your-regex-here]'))

The !newData.hasChildren() condition is included above to prevent the rule from being bypassed by writing nested data.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading