removeNonAlphaNumeric method
Removes all characters that are not letters or numbers.
Implementation
String removeNonAlphaNumeric({bool allowSpace = false}) {
// Define the regex based on whether spaces are allowed.
final RegExp regExp = allowSpace ? RegExp('[^A-Za-z0-9 ]') : RegExp('[^A-Za-z0-9]');
// Replace all non-matching characters.
return replaceAll(regExp, '');
}