debian-mirror-gitlab/app/assets/javascripts/projects/project_name_rules.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
675 B
JavaScript
Raw Normal View History

2023-03-04 22:38:38 +05:30
import { __ } from '~/locale';
2023-04-23 21:23:45 +05:30
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, emojis, spaces, dots, underscores, dashes, or pluses.',
),
};
const rulesReg = [START_RULE, CONTAINS_RULE];
2023-03-04 22:38:38 +05:30
/**
*
* @param {string} text
* @returns {string} msg
*/
2023-04-23 21:23:45 +05:30
export const checkRules = (text) => {
2023-03-04 22:38:38 +05:30
for (const item of rulesReg) {
if (!item.reg.test(text)) {
return item.msg;
}
}
return '';
2023-04-23 21:23:45 +05:30
};