search-domain-validator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Search Domain Name Validator

域名搜索验证器

Overview

概述

This skill enables Claude to validate domain name formats, check domain availability status, and search for available domain names based on keywords. Claude will use this skill to implement domain validation logic, integrate with domain availability APIs, and provide domain search functionality.
此Skill可让Claude验证域名格式、检查域名可用性状态,并基于关键词搜索可用域名。Claude将使用此Skill实现域名验证逻辑、集成域名可用性API,并提供域名搜索功能。

When to Use This Skill

何时使用此Skill

This skill activates automatically when users:
  • Need to validate domain name format or syntax
  • Want to check if a domain is available for registration
  • Need to search for available domain names based on keywords
  • Require domain validation in forms or applications
  • Need to verify domain name compliance with RFC standards
  • Want to implement domain suggestion features
当用户有以下需求时,该Skill会自动激活:
  • 需要验证域名格式或语法
  • 想要检查某个域名是否可注册
  • 需要基于关键词搜索可用域名
  • 需要在表单或应用中实现域名验证
  • 需要核验域名是否符合RFC标准
  • 想要实现域名推荐功能

Project Context Discovery

项目上下文探查

Before providing domain validation guidance, discover the project's context:
  1. Scan Project Documentation:
    • Check for existing domain validation logic
    • Review form validation patterns
    • Look for API integration patterns
    • Check for environment variable usage
  2. Identify Existing Patterns:
    • Review validation libraries in use
    • Check for API client patterns
    • Review error handling approaches
    • Check for domain-related utilities
  3. Use Project-Specific Skills:
    • Check for
      [project]-domain-validator
      skill
    • Review project-specific validation patterns
    • Follow project's validation standards
在提供域名验证指导之前,请先探查项目的上下文:
  1. 扫描项目文档:
    • 检查是否已有域名验证逻辑
    • 查看表单验证模式
    • 寻找API集成模式
    • 检查环境变量的使用方式
  2. 识别现有模式:
    • 查看正在使用的验证库
    • 检查API客户端模式
    • 回顾错误处理方法
    • 查看与域名相关的工具类
  3. 使用项目特定Skill:
    • 检查是否存在
      [project]-domain-validator
      Skill
    • 查看项目特定的验证模式
    • 遵循项目的验证标准

Core Capabilities

核心能力

1. Domain Format Validation

1. 域名格式验证

Validate domain names according to RFC 1035 and RFC 1123 standards.
Domain Name Rules:
  • Length: 1-253 characters total
  • Labels: Up to 63 characters each
  • Characters: Letters (a-z, A-Z), digits (0-9), hyphens (-)
  • Labels cannot start or end with hyphens
  • TLD (top-level domain) required
  • Cannot contain consecutive hyphens
Validation Implementation:
typescript
// TypeScript/JavaScript domain validation
function isValidDomain(domain: string): boolean {
  if (!domain || domain.length > 253) {
    return false;
  }

  // RFC 1035 compliant regex
  const domainRegex = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
  
  if (!domainRegex.test(domain)) {
    return false;
  }

  // Check label length (max 63 chars)
  const labels = domain.split('.');
  for (const label of labels) {
    if (label.length > 63 || label.length === 0) {
      return false;
    }
    // Labels cannot start or end with hyphen
    if (label.startsWith('-') || label.endsWith('-')) {
      return false;
    }
  }

  return true;
}
Python Validation:
python
import re

def is_valid_domain(domain: str) -> bool:
    """Validate domain name format according to RFC 1035 and RFC 1123."""
    if not domain or len(domain) > 253:
        return False
    
    # RFC 1035 compliant regex
    domain_pattern = r'^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$'
    
    if not re.match(domain_pattern, domain, re.IGNORECASE):
        return False
    
    # Check label length (max 63 chars)
    labels = domain.split('.')
    for label in labels:
        if len(label) > 63 or len(label) == 0:
            return False
        # Labels cannot start or end with hyphen
        if label.startswith('-') or label.endswith('-'):
            return False
    
    return True
NestJS Validation:
typescript
import { IsString, Matches, MaxLength, ValidateIf } from 'class-validator';

export class DomainDto {
  @IsString()
  @MaxLength(253)
  @Matches(
    /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i,
    {
      message: 'Invalid domain name format',
    }
  )
  domain: string;
}
根据RFC 1035和RFC 1123标准验证域名。
域名规则:
  • 总长度:1-253个字符
  • 标签:每个标签最多63个字符
  • 字符:字母(a-z, A-Z)、数字(0-9)、连字符(-)
  • 标签不能以连字符开头或结尾
  • 必须包含顶级域名(TLD)
  • 不能包含连续的连字符
验证实现:
typescript
// TypeScript/JavaScript domain validation
function isValidDomain(domain: string): boolean {
  if (!domain || domain.length > 253) {
    return false;
  }

  // RFC 1035 compliant regex
  const domainRegex = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
  
  if (!domainRegex.test(domain)) {
    return false;
  }

  // Check label length (max 63 chars)
  const labels = domain.split('.');
  for (const label of labels) {
    if (label.length > 63 || label.length === 0) {
      return false;
    }
    // Labels cannot start or end with hyphen
    if (label.startsWith('-') || label.endsWith('-')) {
      return false;
    }
  }

  return true;
}
Python验证:
python
import re

def is_valid_domain(domain: str) -> bool:
    """Validate domain name format according to RFC 1035 and RFC 1123."""
    if not domain or len(domain) > 253:
        return False
    
    # RFC 1035 compliant regex
    domain_pattern = r'^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$'
    
    if not re.match(domain_pattern, domain, re.IGNORECASE):
        return False
    
    # Check label length (max 63 chars)
    labels = domain.split('.')
    for label in labels:
        if len(label) > 63 or len(label) == 0:
            return False
        # Labels cannot start or end with hyphen
        if label.startswith('-') or label.endswith('-'):
            return False
    
    return True
NestJS验证:
typescript
import { IsString, Matches, MaxLength, ValidateIf } from 'class-validator';

export class DomainDto {
  @IsString()
  @MaxLength(253)
  @Matches(
    /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i,
    {
      message: 'Invalid domain name format',
    }
  )
  domain: string;
}

2. Domain Availability Checking

2. 域名可用性检查

Check if a domain is available for registration using domain availability APIs.
Common Domain Availability APIs:
  • Namecheap API
  • GoDaddy API
  • Name.com API
  • WHOIS lookups (for basic checks)
Namecheap API Integration:
typescript
// Namecheap domain availability check
async function checkDomainAvailability(domain: string): Promise<boolean> {
  const apiUser = process.env.NAMECHEAP_API_USER;
  const apiKey = process.env.NAMECHEAP_API_KEY;
  const clientIp = process.env.NAMECHEAP_CLIENT_IP;
  
  const url = `https://api.namecheap.com/xml.response?ApiUser=${apiUser}&ApiKey=${apiKey}&UserName=${apiUser}&Command=namecheap.domains.check&ClientIp=${clientIp}&DomainList=${domain}`;
  
  try {
    const response = await fetch(url);
    const xml = await response.text();
    
    // Parse XML response
    // Available domains return <DomainCheckResult Domain="example.com" Available="true"/>
    return xml.includes('Available="true"');
  } catch (error) {
    console.error('Error checking domain availability:', error);
    throw error;
  }
}
GoDaddy API Integration:
typescript
// GoDaddy domain availability check
async function checkGoDaddyAvailability(domain: string): Promise<boolean> {
  const apiKey = process.env.GODADDY_API_KEY;
  const apiSecret = process.env.GODADDY_API_SECRET;
  
  const url = `https://api.godaddy.com/v1/domains/available?domain=${domain}`;
  
  try {
    const response = await fetch(url, {
      headers: {
        'Authorization': `sso-key ${apiKey}:${apiSecret}`,
        'Content-Type': 'application/json',
      },
    });
    
    const data = await response.json();
    return data.available === true;
  } catch (error) {
    console.error('Error checking domain availability:', error);
    throw error;
  }
}
NestJS Service Example:
typescript
import { Injectable } from '@nestjs/common';
import { HttpService } from '@nestjs/axios';
import { firstValueFrom } from 'rxjs';

@Injectable()
export class DomainService {
  constructor(private httpService: HttpService) {}

  async checkAvailability(domain: string): Promise<boolean> {
    const apiKey = process.env.DOMAIN_API_KEY;
    const apiSecret = process.env.DOMAIN_API_SECRET;
    
    try {
      const response = await firstValueFrom(
        this.httpService.get(`https://api.example.com/domains/check`, {
          params: { domain },
          headers: {
            'Authorization': `Bearer ${apiKey}`,
          },
        })
      );
      
      return response.data.available;
    } catch (error) {
      throw new Error(`Failed to check domain availability: ${error.message}`);
    }
  }
}
使用域名可用性API检查域名是否可注册。
常见域名可用性API:
  • Namecheap API
  • GoDaddy API
  • Name.com API
  • WHOIS查询(用于基础检查)
Namecheap API集成:
typescript
// Namecheap domain availability check
async function checkDomainAvailability(domain: string): Promise<boolean> {
  const apiUser = process.env.NAMECHEAP_API_USER;
  const apiKey = process.env.NAMECHEAP_API_KEY;
  const clientIp = process.env.NAMECHEAP_CLIENT_IP;
  
  const url = `https://api.namecheap.com/xml.response?ApiUser=${apiUser}&ApiKey=${apiKey}&UserName=${apiUser}&Command=namecheap.domains.check&ClientIp=${clientIp}&DomainList=${domain}`;
  
  try {
    const response = await fetch(url);
    const xml = await response.text();
    
    // Parse XML response
    // Available domains return <DomainCheckResult Domain="example.com" Available="true"/>
    return xml.includes('Available="true"');
  } catch (error) {
    console.error('Error checking domain availability:', error);
    throw error;
  }
}
GoDaddy API集成:
typescript
// GoDaddy domain availability check
async function checkGoDaddyAvailability(domain: string): Promise<boolean> {
  const apiKey = process.env.GODADDY_API_KEY;
  const apiSecret = process.env.GODADDY_API_SECRET;
  
  const url = `https://api.godaddy.com/v1/domains/available?domain=${domain}`;
  
  try {
    const response = await fetch(url, {
      headers: {
        'Authorization': `sso-key ${apiKey}:${apiSecret}`,
        'Content-Type': 'application/json',
      },
    });
    
    const data = await response.json();
    return data.available === true;
  } catch (error) {
    console.error('Error checking domain availability:', error);
    throw error;
  }
}
NestJS服务示例:
typescript
import { Injectable } from '@nestjs/common';
import { HttpService } from '@nestjs/axios';
import { firstValueFrom } from 'rxjs';

@Injectable()
export class DomainService {
  constructor(private httpService: HttpService) {}

  async checkAvailability(domain: string): Promise<boolean> {
    const apiKey = process.env.DOMAIN_API_KEY;
    const apiSecret = process.env.DOMAIN_API_SECRET;
    
    try {
      const response = await firstValueFrom(
        this.httpService.get(`https://api.example.com/domains/check`, {
          params: { domain },
          headers: {
            'Authorization': `Bearer ${apiKey}`,
          },
        })
      );
      
      return response.data.available;
    } catch (error) {
      throw new Error(`Failed to check domain availability: ${error.message}`);
    }
  }
}

3. Domain Search Functionality

3. 域名搜索功能

Search for available domain names based on keywords, generating suggestions and alternatives.
Domain Suggestion Algorithm:
typescript
function generateDomainSuggestions(keyword: string, tlds: string[] = ['com', 'io', 'net', 'org']): string[] {
  const suggestions: string[] = [];
  const sanitized = keyword.toLowerCase().replace(/[^a-z0-9-]/g, '');
  
  // Direct combinations
  for (const tld of tlds) {
    suggestions.push(`${sanitized}.${tld}`);
  }
  
  // Common prefixes
  const prefixes = ['get', 'try', 'use', 'my', 'the'];
  for (const prefix of prefixes) {
    for (const tld of tlds) {
      suggestions.push(`${prefix}${sanitized}.${tld}`);
    }
  }
  
  // Common suffixes
  const suffixes = ['app', 'hub', 'ly', 'fy', 'io'];
  for (const suffix of suffixes) {
    for (const tld of tlds) {
      suggestions.push(`${sanitized}${suffix}.${tld}`);
    }
  }
  
  return suggestions;
}
Batch Availability Check:
typescript
async function searchAvailableDomains(keyword: string): Promise<string[]> {
  const suggestions = generateDomainSuggestions(keyword);
  const availableDomains: string[] = [];
  
  // Check availability for all suggestions (with rate limiting)
  for (const domain of suggestions) {
    try {
      const isAvailable = await checkDomainAvailability(domain);
      if (isAvailable) {
        availableDomains.push(domain);
      }
      // Rate limiting delay
      await new Promise(resolve => setTimeout(resolve, 100));
    } catch (error) {
      console.error(`Error checking ${domain}:`, error);
    }
  }
  
  return availableDomains;
}
基于关键词搜索可用域名,生成推荐和替代选项。
域名推荐算法:
typescript
function generateDomainSuggestions(keyword: string, tlds: string[] = ['com', 'io', 'net', 'org']): string[] {
  const suggestions: string[] = [];
  const sanitized = keyword.toLowerCase().replace(/[^a-z0-9-]/g, '');
  
  // Direct combinations
  for (const tld of tlds) {
    suggestions.push(`${sanitized}.${tld}`);
  }
  
  // Common prefixes
  const prefixes = ['get', 'try', 'use', 'my', 'the'];
  for (const prefix of prefixes) {
    for (const tld of tlds) {
      suggestions.push(`${prefix}${sanitized}.${tld}`);
    }
  }
  
  // Common suffixes
  const suffixes = ['app', 'hub', 'ly', 'fy', 'io'];
  for (const suffix of suffixes) {
    for (const tld of tlds) {
      suggestions.push(`${sanitized}${suffix}.${tld}`);
    }
  }
  
  return suggestions;
}
批量可用性检查:
typescript
async function searchAvailableDomains(keyword: string): Promise<string[]> {
  const suggestions = generateDomainSuggestions(keyword);
  const availableDomains: string[] = [];
  
  // Check availability for all suggestions (with rate limiting)
  for (const domain of suggestions) {
    try {
      const isAvailable = await checkDomainAvailability(domain);
      if (isAvailable) {
        availableDomains.push(domain);
      }
      // Rate limiting delay
      await new Promise(resolve => setTimeout(resolve, 100));
    } catch (error) {
      console.error(`Error checking ${domain}:`, error);
    }
  }
  
  return availableDomains;
}

Best Practices

最佳实践

Validation

验证

  • Always validate domain format before checking availability
  • Handle edge cases (internationalized domain names, subdomains)
  • Provide clear error messages for invalid domains
  • Consider validating TLD separately if needed
  • 在检查可用性之前,务必先验证域名格式
  • 处理边缘情况(国际化域名、子域名)
  • 为无效域名提供清晰的错误提示
  • 如果需要,可单独验证顶级域名(TLD)

API Integration

API集成

  • Store API credentials in environment variables
  • Implement rate limiting to avoid API throttling
  • Handle API errors gracefully
  • Cache availability results when appropriate
  • Use appropriate timeouts for API calls
  • 将API凭证存储在环境变量中
  • 实现速率限制,避免API限流
  • 优雅处理API错误
  • 适当时缓存可用性检查结果
  • 为API调用设置合理的超时时间

User Experience

用户体验

  • Provide real-time validation feedback
  • Show domain suggestions as user types
  • Display availability status clearly
  • Offer alternative TLD suggestions
  • Handle loading states during availability checks
  • 提供实时验证反馈
  • 在用户输入时显示域名推荐
  • 清晰展示可用性状态
  • 提供替代顶级域名的推荐
  • 在可用性检查期间处理加载状态

Security

安全

  • Never expose API keys in client-side code
  • Validate and sanitize all user input
  • Implement proper error handling
  • Use HTTPS for all API communications
  • Follow API provider's security guidelines
  • 切勿在客户端代码中暴露API密钥
  • 验证并清理所有用户输入
  • 实现完善的错误处理
  • 所有API通信使用HTTPS
  • 遵循API提供商的安全指南

Example User Requests

用户请求示例

Example 1: "Validate this domain: example.com"
  • Use format validation to check if the domain follows RFC standards
  • Return validation result with specific error details if invalid
Example 2: "Check if example.com is available"
  • Validate domain format first
  • Call domain availability API
  • Return availability status
Example 3: "Search for available domains with keyword 'techstartup'"
  • Generate domain suggestions based on keyword
  • Check availability for each suggestion
  • Return list of available domains with pricing if available
Example 4: "Implement domain validation in this form"
  • Add domain validation to form component
  • Integrate real-time validation
  • Provide user feedback for invalid domains
示例1:"验证这个域名:example.com"
  • 使用格式验证检查域名是否符合RFC标准
  • 返回验证结果,若无效则提供具体错误详情
示例2:"检查example.com是否可用"
  • 先验证域名格式
  • 调用域名可用性API
  • 返回可用性状态
示例3:"搜索包含关键词'techstartup'的可用域名"
  • 基于关键词生成域名推荐
  • 检查每个推荐域名的可用性
  • 返回可用域名列表(若有价格信息也一并提供)
示例4:"在这个表单中实现域名验证"
  • 为表单组件添加域名验证
  • 集成实时验证功能
  • 为无效域名提供用户反馈

Common Domain TLDs

常见域名顶级域名(TLD)

Generic TLDs:
  • .com, .net, .org, .info, .biz
New gTLDs:
  • .app, .dev, .io, .ai, .tech, .online, .xyz
Country Code TLDs:
  • .us, .uk, .ca, .au, .de, .fr, .jp
When implementing domain search, consider including popular TLDs relevant to the user's context or industry.
通用顶级域名:
  • .com, .net, .org, .info, .biz
新通用顶级域名:
  • .app, .dev, .io, .ai, .tech, .online, .xyz
国家/地区代码顶级域名:
  • .us, .uk, .ca, .au, .de, .fr, .jp
在实现域名搜索时,请考虑包含与用户上下文或行业相关的热门顶级域名。