【问题标题】:Validate email format in firestore security rules在 Firestore 安全规则中验证电子邮件格式
【发布时间】:2020-06-01 15:31:30
【问题描述】:

我需要确保如果用户正在更新其电子邮件,它应该是正确的电子邮件地址(至少包括“@”并以“.xxx”结尾)

我知道我必须使用matches。我试过了:

request.resource.data.email.matches(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i)

但它似乎不符合 RE2:

i  firestore: Change detected, updating rules...
⚠  firestore.rules:30:63 - ERROR Unexpected '_'.
⚠  firestore.rules:30:63 - ERROR Unexpected '_'.
⚠  firestore.rules:30:63 - ERROR mismatched input '_' expecting {'&&', '.', '==', '>', '>=', '[', '<', '<=', '-', '%', '!=', '||', '+', '}', ';', '/', '*', '?', 'in', 'is'}
⚠  firestore.rules:30:81 - ERROR token recognition error at: '\'
⚠  firestore.rules:30:82 - ERROR token recognition error at: '\'
⚠  firestore.rules:30:94 - ERROR Unexpected '$'.
⚠  firestore.rules:30:95 - ERROR Missing 'match' keyword before path.
⚠  firestore.rules:30:97 - ERROR mismatched input ')' expecting {'{', '/', PATH_SEGMENT}
⚠  firestore.rules:48:3 - ERROR Unexpected '}'.
✔  firestore: Rules updated.

某处是否有正确的电子邮件 RE2 正则表达式?我找不到。

【问题讨论】:

    标签: google-cloud-firestore firebase-security


    【解决方案1】:

    根据API documentation,matches() 接受一个字符串参数。这意味着您应该将正则表达式放在双引号内,以告诉语言您有一个字符串值。

    【讨论】:

    • 好的,谢谢!现在我的正则表达式似乎不起作用。知道在哪里可以找到有效的吗?
    • 如果您有新问题,请单独发布。不过,我要指出的是,要求对非现场材料的引用是 Stack Overflow 的主题。
    猜你喜欢
    • 2017-01-17
    • 1970-01-01
    • 2016-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-26
    • 2018-04-02
    • 2012-01-03
    相关资源
    最近更新 更多