validateNIC static method

String? validateNIC(
  1. String? value
)

Validate given NIC, this method only for SL

  • value : NIC number

Implementation

static String? validateNIC(String? value) {
  const pattern1 = r'^[0-9]{9}[vV]$';
  const pattern2 = r'^[0-9]{12}$';
  final RegExp regex1 = RegExp(pattern1);
  final RegExp regex2 = RegExp(pattern2);
  if (value != null &&
      value.isNotEmpty &&
      (regex1.hasMatch(value) || regex2.hasMatch(value))) {
    return null;
  } else if (value == null || value.isEmpty) {
    return 'This filed is required';
  } else {
    return 'Please enter valid NIC number';
  }
}