summaryrefslogtreecommitdiffstats
path: root/ui/src/utils.ts
diff options
context:
space:
mode:
authorTony Antonov <MM263@users.noreply.github.com>2020-07-10 19:15:53 -0600
committerGitHub <noreply@github.com>2020-07-10 21:15:53 -0400
commit8d2465989230fae7d9aae334a67a726fd6ced912 (patch)
treed24ddd793036463314a63b201860221dc37503f4 /ui/src/utils.ts
parent7a9a973c897ee9ebd68c071e2e17e561567004b6 (diff)
Forbid users to use empty titles for posts (#930)
- Add a regex that checks if string contains anything but whitespace - Check for whitespace-only titles on post creation and edit - Trim whitespace from titles before saving - Add frontend validation to title
Diffstat (limited to 'ui/src/utils.ts')
-rw-r--r--ui/src/utils.ts9
1 files changed, 9 insertions, 0 deletions
diff --git a/ui/src/utils.ts b/ui/src/utils.ts
index 2f06b70c..6276519b 100644
--- a/ui/src/utils.ts
+++ b/ui/src/utils.ts
@@ -986,3 +986,12 @@ function canUseWebP() {
// // very old browser like IE 8, canvas not supported
// return false;
}
+
+export function validTitle(title?: string): boolean {
+ // Initial title is null, minimum length is taken care of by textarea's minLength={3}
+ if (title === null || title.length < 3) return true;
+
+ const regex = new RegExp(/.*\S.*/, 'g');
+
+ return regex.test(title);
+}