export function validateMobile(value: string): string | null {
  const trimmed = value.trim();
  if (!trimmed) return null;
  if (!/^1\d{10}$/.test(trimmed)) return '手机号格式不正确（11位）';
  return null;
}

export function validateLandline(value: string): string | null {
  const trimmed = value.trim();
  if (!trimmed || trimmed === '-') return null;
  const digits = trimmed.replace(/\D/g, '');
  if (digits.length < 7 || digits.length > 12) return '座机号码格式不正确';
  return null;
}

export function validateEmail(value: string): string | null {
  const trimmed = value.trim();
  if (!trimmed) return null;
  if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(trimmed)) return '邮箱格式不正确';
  return null;
}

export function validateContactPhones(mobile: string, phone: string): string | null {
  if (!mobile.trim() && (!phone.trim() || phone.trim() === '-')) {
    return '联系人手机与座机至少填写一项';
  }
  const mobileError = validateMobile(mobile);
  if (mobileError) return mobileError;
  const phoneError = validateLandline(phone);
  if (phoneError) return phoneError;
  return null;
}
