2016-07-16 39 views
1

我想驗證$username長度大於5個字符且短於24個字符的如何驗證Firebase規則中的位置路徑?

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

(如果可能的話),我該怎麼辦久嗎?

回答

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": {} 
      } 
     } 
    } 
}