0
votes

I'm trying to validate submitted data against Regex expressions in Firestore Security Rules. I've read through the documentation, but I'm still unsure how to write them.

I read through the Regex documentation here https://firebase.google.com/docs/reference/security/database/regex , but it doesn't really show how to use it in Firestore. I tried using an 'allow validate' rule and copy/pasted a regex expression from the docs, but I'm getting all kinds of errors.

Here's what I tried:

link

Do I need to put it in a format like this? (From the docs) allow create: if !("ranking" in request.resource.data)? If so, how do I use a regex expression with it?

1

1 Answers

2
votes

It looks like you're trying to start a regex with /. That's not going to work - it's not like perl. Slash starts a path object. Might want to check the API documentation on this. You should just be passing a plain string to matches() that contains the regex to match.

https://firebase.google.com/docs/reference/rules/rules.String#matches