itemCode static method

String? itemCode(
  1. String? value
)

Validate item code

Implementation

static String? itemCode(String? value) {
  if (value == null || value.isEmpty) {
    return 'Item code is required';
  }

  if (!RegexPatterns.code.hasMatch(value)) {
    return 'Item code can only contain letters, numbers, hyphens and underscores';
  }

  if (value.length < 2) {
    return 'Item code must be at least 2 characters';
  }

  if (value.length > 20) {
    return 'Item code must be at most 20 characters';
  }

  return null;
}