validateFileName function

String? validateFileName(
  1. String? value
)

Validates if the input string is a valid file name. Returns null if valid, or an error message string if invalid.

Implementation

String? validateFileName(String? value) {
  if (value == null || value.isEmpty) {
    return 'Please enter a file name';
  }
  // This regex checks for invalid characters in file names. It's basic
  // and might need adjustments.
  if (RegExp(r'[\\/:*?"<>|]').hasMatch(value)) {
    return 'File name contains invalid characters';
  }
  return null;
}