filesystemFormFieldValidator method

String? filesystemFormFieldValidator(
  1. String? storeName
)

Use filesystemSanitiser publicly, in a validation situation such as in FormField

This is useful to validate user-facing input for store names (such as in FormFields), and ensure that they:

  • comply with limitations of the filesystem
  • don't cause problems where sanitised input causes duplication

Therefore, to prevent unexpected errors on construction, it is recommended to use this as a validator for user inputted store names: it can be put right in the validator property!

A null output means the string is valid, otherwise appropriate error text is outputted (in English).

Implementation

String? filesystemFormFieldValidator(String? storeName) {
  try {
    filesystemSanitiseValidate(
      inputString: storeName ?? '',
      throwIfInvalid: true,
    );
    return null;
  } on InvalidFilesystemString catch (e) {
    return e.toStringUserFriendly();
  }
}