Reputation: 709
I would like to validate $username
length to be longer than 5 character and shorter than 24 character
{
"rules": {
"user": {
"$username": {
".write": "auth != null",
"uid": {},
"created": {},
"lastlogin": {}
}
}
}
}
(if it's possible) How can i do that?
Upvotes: 1
Views: 472
Reputation: 16
you can validate the $username with a regex
{
"rules": {
"user": {
"$username": {
".write": "auth != null",
".validate": "$username.matches(/^.{6,23}$/)"
}
}
}
}
Upvotes: 0
Reputation: 709
Yes it is possible:
{
"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": {}
}
}
}
}
Upvotes: 1