cnic static method

Validator cnic({
  1. String message = 'Invalid CNIC',
})

Pakistan CNIC validator (simple): 13 digits OR formatted 5-7-1 (xxxxx-xxxxxxx-x) CNIC validator (Pakistan specific: 5-7-1 format)

Implementation

/// CNIC validator (Pakistan specific: 5-7-1 format)
static Validator cnic({String message = 'Invalid CNIC'}) {
// Allows formats: 12345-1234567-1 OR 1234512345671
final cnicRegex = RegExp(r'^\d{5}-?\d{7}-?\d{1}$');
return (String? value) {
  if (value == null || !cnicRegex.hasMatch(value)) {
    return message;
  }
  return null;
};
}