15856: Adds name validation to projects and collection edit/create dialogs.
[arvados-workbench2.git] / src / validators / valid-name.tsx
diff --git a/src/validators/valid-name.tsx b/src/validators/valid-name.tsx
new file mode 100644 (file)
index 0000000..468811d
--- /dev/null
@@ -0,0 +1,14 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+
+const ERROR_MESSAGE = "Name cannot be '.' or '..' or contain '/' characters";
+
+export const invalidNamingRules = [/\//, /^\.{1,2}$/];
+
+export const validName = (value: string) => {
+    return invalidNamingRules.find(aRule => value.match(aRule) !== null)
+        ? ERROR_MESSAGE
+        : undefined;
+};