]> Untitled Git - lemmy-ui.git/blob - src/shared/utils/helpers/valid-title.ts
Expanded the RegEx to check if the title contains new line caracters. Should fix...
[lemmy-ui.git] / src / shared / utils / helpers / valid-title.ts
1 export default function validTitle(title?: string): boolean {
2   // Initial title is null, minimum length is taken care of by textarea's minLength={3}
3   if (!title || title.length < 3) return true;
4
5   /*
6     Test if the Title is in a valid format:
7       (?=.*\S.*) checks if the title consists of only whitespace characters
8       (?=^[^\r\n]+$) checks if the title contains newlines 
9   */
10   const regex = new RegExp(/(?=(.*\S.*))(?=^[^\r\n]+$)/, "g");
11
12   return regex.test(title);
13 }