Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / shared / validation / validate-tag.js
blob7704b13b203036cab809a8cc1700dd6a29666722
1 'use strict';
3 var MAX_TAG_LENGTH = 20;
4 var MAX_STAFF_TAG_LENGTH = 50;
6 var getMaxTagLength = function(isStaff) {
7 return isStaff ? MAX_STAFF_TAG_LENGTH : MAX_TAG_LENGTH;
8 };
10 var validateTag = function(tagName, isStaff) {
11 var reservedTagTestRegex = /:/;
12 var isValid = true;
13 var messageList = [];
15 if (!isStaff && reservedTagTestRegex.test(tagName)) {
16 messageList.push('Tags can not use `:` colons.');
17 isValid = false;
19 var tagLength = !!tagName && tagName.length;
20 var maxTagLength = getMaxTagLength(isStaff);
21 if (!tagLength || tagLength <= 0 || tagLength > maxTagLength) {
22 messageList.push('Tags must be between 1 and ' + maxTagLength + ' characters in length.');
23 isValid = false;
26 return {
27 isValid: isValid,
28 messages: messageList
32 module.exports = {
33 validateTag: validateTag,
34 getMaxTagLength: getMaxTagLength