validateName function

String? validateName(
  1. BuildContext context,
  2. String? value
)

Implementation

String? validateName(BuildContext context,  String? value) {
  if (value == null || value.isEmpty) {
    return S.of(context).please_enter_a_first_and_last_name;
  }
  Pattern pattern =  r"^[a-zA-ZÀ-ÿ\s\'-]+$";
  RegExp regex = RegExp(pattern as String);
  if (!regex.hasMatch(value)) {
    return S.of(context).name_can_only_contain_alphabetic_characters;
  }
  return null;
}