Как я могу ограничить символы для имени пользователя в правилах Firestore? Я пробовал проверять каждый символ один за другим, но это не сработало

     function validateChar1(sername) {

     return sername[0] == "a" || sername[0] == "b" || sername[0] == "c" || sername[0] == "d" || sername[0] == "e" || sername[0] == "f" || sername[0] == "g" || sername[0] == "h"
        || sername[0] == "i" || sername[0] == "j" || sername[0] == "k" || sername[0] == "l" || sername[0] == "m" || sername[0] == "n" || sername[0] == "o" || sername[0] == "p"
  || sername[0] == "q" || sername[0] == "r" || sername[0] == "s" || sername[0] == "t" || sername[0] == "u" || sername[0] == "v" || sername[0] == "w" || sername[0] == "x"
  || sername[0] == "y" || sername[0] == "z" || sername[0] == "0" || sername[0] == "1" || sername[0] == "2" || sername[0] == "3" || sername[0] == "4" || sername[0] == "5" 
  || sername[0] == "6" || sername[0] == "7" || sername[0] == "8" || sername[0] == "9" || sername[0] == "." || sername[0] == "_"
    }

    function validateChar3(sername) {

    return sername[2] == "a" || sername[2] == "b" || sername[2] == "c" || sername[2] == "d" || sername[2] == "e" || sername[2] == "f" || sername[2] == "g" || sername[2] == "h"
        || sername[2] == "i" || sername[2] == "j" || sername[2] == "k" || sername[2] == "l" || sername[2] == "m" || sername[2] == "n" || sername[2] == "o" || sername[2] == "p"
  || sername[2] == "q" || sername[2] == "r" || sername[2] == "s" || sername[2] == "t" || sername[2] == "u" || sername[2] == "v" || sername[2] == "w" || sername[2] == "x"
  || sername[2] == "y" || sername[2] == "z" || sername[2] == "0" || sername[2] == "1" || sername[2] == "2" || sername[2] == "3" || sername[2] == "4" || sername[2] == "5" 
  || sername[2] == "6" || sername[2] == "7" || sername[2] == "8" || sername[2] == "9" || sername[2] == "." || sername[2] == "_" || sername.size() < 3;
    }



    function validateUsername(username) {

    return validateChar1(username) && validateChar2(username) && validateChar3(username) && validateChar4(username) && validateChar5(username) &&
        validateChar6(username) && validateChar7(username) && validateChar8(username) && validateChar9(username) && validateChar10(username) &&
  validateChar11(username) && validateChar12(username) && validateChar13(username) && validateChar14(username) && validateChar15(username) 
    }
0
Lukas123321 10 Мар 2018 в 23:57

1 ответ

Лучший ответ

Прочтите Справочник по правилам Cloud Firestore. В разделе string вы найдете matches. Это позволяет вам сравнивать значение с регулярным выражением. Вы можете создать регулярное выражение для проверки только разрешенных символов для вашего имени пользователя.

2
Jason Berryman 11 Мар 2018 в 00:24