validateFirebaseProjectId function

ValidationResult validateFirebaseProjectId(
  1. String id
)

Validate Firebase project ID

Implementation

ValidationResult validateFirebaseProjectId(String id) {
  if (id.isEmpty) {
    return const ValidationResult.invalid(
      'Firebase project ID cannot be empty',
    );
  }

  if (id.contains(' ')) {
    return const ValidationResult.invalid(
      'Firebase project ID cannot contain spaces',
    );
  }

  // Firebase project ID pattern: lowercase, numbers, hyphens
  final RegExp validPattern = RegExp(r'^[a-z][a-z0-9-]*[a-z0-9]$');
  if (!validPattern.hasMatch(id) && id.length > 1) {
    return const ValidationResult.invalid(
      'Firebase project ID must start with a letter, contain only lowercase letters, numbers, and hyphens, and end with a letter or number',
    );
  }

  // Single character check
  if (id.length == 1 && !RegExp(r'^[a-z]$').hasMatch(id)) {
    return const ValidationResult.invalid(
      'Firebase project ID must start with a letter',
    );
  }

  // Length check (Firebase allows 6-30 characters)
  if (id.length < 6 || id.length > 30) {
    return const ValidationResult.invalid(
      'Firebase project ID must be between 6 and 30 characters',
    );
  }

  return const ValidationResult.valid();
}