chore: initial commit
Some checks failed
Synchronize to Gitee / repo-sync (push) Has been cancelled
Typos Checking / Spell Check with Typos (push) Has been cancelled

This commit is contained in:
2026-06-23 11:56:23 +08:00
commit 72e2110987
2883 changed files with 367388 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
// 邮箱校验
export const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
// 手机号校验11位
export const phoneRegex = /^\d{11}$/;
// 密码校验8-32位
export const passwordLengthRegex = /^.{8,32}$/;
// 密码校验,必须包含数字和字母,特殊符号范围校验
export const passwordWordRegex = /^(?=.*\d)(?=.*[a-zA-Z])[0-9a-zA-Z!@#$%^&*()_+.]+$/;
// Git地址校验
export const gitRepositoryUrlRegex = /\.git$/;
// Webhook 地址校验,允许 HTTP / HTTPS
export const httpUrlRegex = /^https?:\/\/[^\s/$.?#].[^\s]*$/i;
/**
* 校验邮箱
* @param email 邮箱
* @returns boolean
*/
export function validateEmail(email: string): boolean {
return emailRegex.test(email);
}
/**
* 校验手机号
* @param phone 手机号
* @returns boolean
*/
export function validatePhone(phone: string): boolean {
return phoneRegex.test(phone);
}
/**
* 校验密码长度
* @param password 密码
* @returns boolean
*/
export function validatePasswordLength(password: string): boolean {
return passwordLengthRegex.test(password);
}
/**
* 校验密码组成
* @param password 密码
* @returns boolean
*/
export function validateWordPassword(password: string): boolean {
return passwordWordRegex.test(password);
}
/**
* 校验密码
* @param password 密码
* @returns boolean
*/
export function validatePassword(password: string): boolean {
return validatePasswordLength(password) && validateWordPassword(password);
}
/**
* 校验 HTTP / HTTPS 地址
* @param url 地址
* @returns boolean
*/
export function validateHttpUrl(url: string): boolean {
return httpUrlRegex.test(url.trim());
}
export function getPatternByAreaCode(code: string): RegExp | null {
switch (code) {
case '+86': // 中国大陆
return /^\d{10,12}$/;
case '+852': // 香港
return /^\d{8}$/;
case '+853': // 澳门
return /^\d{8}$/;
case '+886': // 台湾
return /^\d{8,11}$/;
default: // 其他
return /^\d+$/;
}
}