kirtan403
kirtan403

Reputation: 7411

Is it possible to validate key using firebase security rules?

I have a list year wise inside a node. Is it possible to validate key using .validate or something?

like I have a list like this:

"list": {
    "year-2015": {
        // data
    },
    "year-2016": {
        //data
    }
    // etc etc
}

Can I validate key using regex /year-[0-9]{4}/ in security rules?

Upvotes: 4

Views: 770

Answers (1)

cartant
cartant

Reputation: 58400

Yes. Validation rules can be used to validate keys.

You could define a rule like this:

{
  "rules": {
    "list": {
      "$key": {
        ".validate": "$key.matches(/^year-[0-9]{4}$/)"
      }
    }
  }
}

Upvotes: 3

Related Questions