Files
thebet365/packages/shared/src/playerUsername.js
2026-06-13 17:38:25 +08:00

16 lines
654 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** 玩家用户名仅英文字母与数字732 位 */
export const PLAYER_USERNAME_PATTERN = /^[a-zA-Z0-9]{7,32}$/;
export const PLAYER_USERNAME_RULE_MESSAGE = '玩家用户名仅可使用英文字母和数字732 位),不可含中文或特殊符号';
export function isValidPlayerUsername(username) {
return PLAYER_USERNAME_PATTERN.test(username.trim());
}
export function assertPlayerUsername(username) {
const trimmed = username.trim();
if (!trimmed) {
throw new Error('玩家用户名不能为空');
}
if (!isValidPlayerUsername(trimmed)) {
throw new Error(PLAYER_USERNAME_RULE_MESSAGE);
}
}