Firestore has constraints on IDs (https://firebase.google.com/docs/firestore/quotas)
What is the Javascript regex for checking the constraints on the following:
/
).
) or double periods (..
)__.*__
Let's look at these points:
Must be valid UTF-8 characters
I would assume that this is more an issue of your programing language of choice, at least until you tell us that you have raw octets and want a regular expression to validate that a sequence of raw octets is a valid UTF-8 sequence.
Must be no longer than 1,500 bytes
This will mean something like .{1,1500}
Cannot contain a forward slash
This will mean something like [^/]{1,1500}
instead of .{1,1500}
.
Cannot solely consist of a single period or double periods.
This means something like (?!\.\.?)
.
Cannot match the regular expression
__.*__
This means something like (?!__.*__)
. Maybe it should mean that no ID is allowed to start with __
and to end with __
, but maybe it means that no ID is allowed to contain a substring that starts/ends with __
. My approach plays it safe and rejects anything that contains the substring.
Combining the above we get something like:
^(?!\.\.?$)(?!.*__.*__)([^/]{1,1500})$
Shortening the maximum length to something sensible like 10, some test cases:
Acceptfoo
foo.
foo..
Reject
bar/
12345678901
foo__bar__
.
..
Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With