Validate a Firebase Key is an integer

前端 未结 2 689
后悔当初
后悔当初 2021-01-05 23:41

Here is the database schema:

Here are the rules:

\"notifications\": {
   \"$year\": {
      \".read\": \"false\",
      \".write\": \"!data.         


        
2条回答
  •  隐瞒了意图╮
    2021-01-06 00:24

    To validate that a key is a number:

    {
      "$key": {
         ".validate": "$key.matches(/^[0-9]+$/)"
      }
    }
    

    But please read about array-like behaviors in Firebase. Hint: probably use a prefix like "y2015", "m12", etc. to avoid some unexpected results with using numbers.

提交回复
热议问题