Files
thebet365/packages/shared/src/playerUsername.ts
Mars 312c3c5816 feat(player): 注册账号、登录双模式与移动端性能优化
注册必填 7-32 位账号,手机号区号/本地号分存;登录默认账号模式并支持切换手机号登录;Player i18n 拆包与赛事接口优化。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-12 10:56:51 +08:00

20 lines
670 B
TypeScript
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: string): boolean {
return PLAYER_USERNAME_PATTERN.test(username.trim());
}
export function assertPlayerUsername(username: string): void {
const trimmed = username.trim();
if (!trimmed) {
throw new Error('玩家用户名不能为空');
}
if (!isValidPlayerUsername(trimmed)) {
throw new Error(PLAYER_USERNAME_RULE_MESSAGE);
}
}