如何在Firebase规则中验证位置路径?

时间:2016-07-16 06:04:27

标签: firebase firebase-realtime-database firebase-security

我想验证$username长度超过5个字符且短于24个字符

{
    "rules": {
        "user": {
            "$username": {
                ".write": "auth != null",
                "uid": {},
                "created": {},
                "lastlogin": {}
            }
        }
    }
}

(如果可能的话)我该怎么做?

2 个答案:

答案 0 :(得分:1)

是的,有可能:

{
    "rules": {
        "user": {
            "$username": {
                ".write": "auth != null",
                ".validate":"newData.hasChildren(['validate_username'])",
                "validate_username":{
                    ".validate":"
                        newData.val() == $username
                        && newData.val().length > 5
                        && newData.val().length < 24
                    "
                },
                "uid": {},
                "created": {},
                "lastlogin": {}
            }
        }
    }
}

答案 1 :(得分:0)

您可以使用正则表达式验证$ username

<dist:module dist:instant="true" />