extension StringExtensions on String {
  // Validation
  bool get isValidEmail {
    return RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$').hasMatch(this);
  }

  bool get isValidPhone {
    return RegExp(r'^1[3-9]\d{9}$').hasMatch(this);
  }

  bool get isValidWalletAddress {
    return RegExp(r'^0x[a-fA-F0-9]{40}$').hasMatch(this);
  }

  // Formatting
  String get capitalize {
    if (isEmpty) return this;
    return '${this[0].toUpperCase()}${substring(1)}';
  }

  String truncate(int maxLength, {String suffix = '...'}) {
    if (length <= maxLength) return this;
    return '${substring(0, maxLength - suffix.length)}$suffix';
  }

  String get maskMiddle {
    if (length <= 8) return this;
    return '${substring(0, 4)}****${substring(length - 4)}';
  }

  String get maskWalletAddress {
    if (length <= 10) return this;
    return '${substring(0, 6)}...${substring(length - 4)}';
  }
}
