Stay organized with collections Save and categorize content based on your preferences.
Regular expression literals can be used to validate client supplied strings. Use string.matches(/pattern/)
to test if a string adheres to a regular expression pattern. The regular expression syntax is not identical to common regular expressions syntax, in particular:
*
+
.
(
)
[
]
{
}
\
work as normal.^
and $
anchors only work if we're using them to match the first or last character in the pattern.i
(ignore case) modifier flag is supportedA regular expression literal is introduced into a security expression using the /pattern/
notation. To test whether a string adheres to a regular expression pattern, use the matches member function of string. The following matches rule checks whether the new data starts with the string foo.
".validate": "newData.val().matches(/^foo/)"
Supported Features
Firebase supports only a subset of typical regular expression features. However, the regular expression syntax should feel familiar.
These are the supported symbols:
Character Meaning\s
\w
\d
\S
\W
\D
predefined character sets for matching whitespace, a word character, or a digit, and their negations (respectively) \
escape, the character following is interpreted literally.
/\/
^
anchor to the beginning of the string. This can only be used as the first letter of the pattern.
/a/
matches "ba", while /^a/
does not. $
anchor to the end of the string. This can only be used as the last letter of the pattern.
/a/
matches "ab", while /a$/
does not. *
matches zero or many of the preceding pattern.
/^a*$/
matches "" and "aaa", but not "b" +
matches one or more of the preceding pattern.
/^a+$/
matches "a" and "aaa", but not "" ?
matches zero or one of the preceding pattern.
/^a?$/
matches "" and "a", but not "aa" .
matches any character
/......../
matches "Firebase" (pattern)
parenthesis groups a pattern into a single unit
/(ab)*/
matches "abab" a|b
matches either a or b
/a|bc/
matches "ac" or "bc" [akz]
a character set, matches any of the included characters.
/[ABCDEF]/
matches only capitalized letters from A to F. [a-z]
a character interval, matches all characters inclusively in the specified range.
/[0-9A-F]+/
matches hexadecimal strings [^0-9]
A leading ^
negates the character set, matching anything other than the specified character set.
An i
trailing the regular expression literal construction (e.g. /yes/i
) indicates the matching will be case insensitive. Other regular expression modifiers are not supported at this time.
Regular expression matching in the Firebase Realtime Database Security Rules is neither greedy nor non-greedy, since it only allows you to detect a match and not to capture portions of the string.
UsageRequire a string to be a date formatted as YYYY-MM-DD between 1900-2099:
".validate": "newData.isString() && newData.val().matches(/^(19|20)[0-9][0-9][-\\/. ](0[1-9]|1[012])[-\\/. ](0[1-9]|[12][0-9]|3[01])$/)"
Require string to be an email address:
".validate": "newData.isString() && newData.val().matches(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}$/i)"
Note: THIS WILL REJECT SOME VALID EMAILS. Validating email address in regular expressions is difficult in general. See this site for more depth on the subject.
Require string to be a basic URL:
".validate": "newData.isString() && newData.val().matches(/^(ht|f)tp(s?):\\/\\/[0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*((0-9)*)*(\\/?)([a-zA-Z0-9\\-\\.\\?\\,\\'\\/\\\\+&=%\\$#_]*)?$/)"
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-15 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-15 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4