voterIdValidator static method

String? voterIdValidator(
  1. String? value, [
  2. String? errorMessage
])

voterIdValidator to validate Voter ID number

validator: (value) => SimpleValidations.voterIdValidator(value, [errorMessage]),

Implementation

static String? voterIdValidator(String? value, [String? errorMessage]) {
  RegExp regex = CustomRegEx.voterIdRegex;
  if (value == null || value.isEmpty) {
    return errorMessage ?? 'Required';
  } else if (value.length != 10) {
    return errorMessage ?? 'Please enter a valid Voter ID number';
  } else if (!regex.hasMatch(value)) {
    return errorMessage ?? 'Please enter a valid Voter ID number';
  }
  return null;
}