alphanumeric static method

bool alphanumeric(
  1. String input, {
  2. bool withSpace = false,
})

Validates whether the given input is alphanumeric.

The input parameter should be a string. The withSpace parameter allows the input string to contain spaces.

Returns true if the input is alphanumeric, false otherwise.

Implementation

static bool alphanumeric(String input, {bool withSpace = false}) {
  String pattern = withSpace ? r'^[a-zA-Z0-9 ]*$' : r'^[a-zA-Z0-9]*$';
  return RegExp(pattern).hasMatch(input);
}