Welcome to mirror list, hosted at ThFree Co, Russian Federation.

project_name_rules.js « projects « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 90f9290ffb801364b390ace3ad4b8b7006322a05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { __ } from '~/locale';

export const START_RULE = {
  reg: /^[a-zA-Z0-9\u{00A9}-\u{1f9ff}_]/u,
  msg: __('Name must start with a letter, digit, emoji, or underscore.'),
};

export const CONTAINS_RULE = {
  reg: /^[a-zA-Z0-9\p{Pd}\u{002B}\u{00A9}-\u{1f9ff}_. ]+$/u,
  msg: __(
    'Name can contain only lowercase or uppercase letters, digits, emoji, spaces, dots, underscores, dashes, or pluses.',
  ),
};

const rulesReg = [START_RULE, CONTAINS_RULE];

/**
 *
 * @param {string} text
 * @returns {string} msg
 */
export const checkRules = (text) => {
  for (const item of rulesReg) {
    if (!item.reg.test(text)) {
      return item.msg;
    }
  }
  return '';
};