call method

  1. @override
String? call(
  1. String attribute,
  2. String value
)
override

Validates whether a value contains only alphanumeric characters.

This method checks if the input value contains only characters from the ranges 'a' to 'z' (both lowercase and uppercase) and '0' to '9'. If the value contains any other characters, it is considered invalid, and an error message is generated using the buildMessage method.

Parameters:

  • attribute: The identifier of the form attribute being validated.
  • value: The value to be validated.

Returns: A validation error message if the value contains non-alphanumeric characters, or null if the value is valid.

Implementation

@override
String? call(String attribute, String value) {
  if (value.isNotEmpty) {
    RegExp exp = RegExp(r"^[a-zA-Z0-9]+$");
    if (!exp.hasMatch(value)) {
      return buildMessage(attribute, value);
    }
  }
  return null;
}