isAscii property

bool isAscii

Checks whether the String is a valid ASCII string.

Example

String foo = 'Hello World';
bool isAscii = foo.isAscii; // returns true;
String foo = 'œ∑´®†¥¨ˆøπ';
bool isAscii = foo.isAscii; // returns false;

Implementation

bool get isAscii {
  if (this.isEmpty) {
    return true;
  }
  final ascii = new RegExp(r'^[\x00-\x7F]+$');
  return ascii.hasMatch(this);
}