validateTemplateName static method
Validates template name format.
templateName
is the template name to validate.
Returns true if the template name is valid.
Throws MessageException if the template name is invalid.
Implementation
static bool validateTemplateName(String templateName) {
if (templateName.isEmpty) {
throw MessageException.invalidContent('Template name cannot be empty.');
}
// Template names should be alphanumeric with underscores
final RegExp validNamePattern = RegExp(r'^[a-zA-Z0-9_]+$');
if (!validNamePattern.hasMatch(templateName)) {
throw MessageException.invalidContent(
'Template name should only contain letters, numbers, and underscores.',
);
}
return true;
}