alphanumeric static method

String? alphanumeric(
  1. String? value, {
  2. String fieldName = 'This field',
})

Validates that the input contains only alphanumeric characters.

Implementation

static String? alphanumeric(
  String? value, {
  String fieldName = 'This field',
}) {
  if (value == null || value.isEmpty) return '$fieldName is required';
  if (!RegExp(r'^[a-zA-Z0-9]+$').hasMatch(value)) {
    return '$fieldName can only contain letters and numbers';
  }
  return null;
}