isValidName property

bool get isValidName

Checks if the string is a valid personal name.

Accepts letters, spaces, hyphens, periods, and apostrophes in typical name formats.

Example:

'John D. O'Connor'.isValidName; // true

Implementation

bool get isValidName {
  final nameRegExp = RegExp(
    r"^\s*([A-Za-z]{1,}([\.,] |[-']| ))+[A-Za-z]+\.?\s*$",
  );
  return nameRegExp.hasMatch(this);
}