// 手机号验证
const isValidPhone = (phone) => {
	// 手机号码正则
	const mobilePattern = /^1[3-9]\d{9}$/;
	// 固定电话正则
	const landlinePattern = /^(0\d{2,3})[- ]?\d{7,8}$/;
	if (mobilePattern.test(phone)) {
		return true
	} else if (landlinePattern.test(phone)) {
		return true
	} else {
		return false
	}
};
const isMobilePhone = (phone) => {
	const mobilePattern = /^1[3-9]\d{9}$/;
	return mobilePattern.test(phone)
}

// 邮箱验证
const isValidEmail = (email) => {
	return /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(email);
};

// URL验证
const isValidUrl = (url) => {
	try {
		new URL(url);
		return true;
	} catch {
		return false;
	}
};

// 身份证号验证
const isValidIdCard = (idCard) => {
	return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(idCard);
};

// 企业统一社会信用代码验证
const isValidCreditCode = (creditCode) => {
	return /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/.test(creditCode);
};

// 密码强度验证（至少包含数字和字母，长度8-20位）
const isValidPassword = (password) => {
	return /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,20}$/.test(password);
};

export {
	isValidPhone,
	isValidEmail,
	isValidUrl,
	isValidIdCard,
	isValidCreditCode,
	isValidPassword,
	isMobilePhone
};