socialSecurityValidator static method

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

socialSecurityValidator to validate social security number

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

Implementation

static String? socialSecurityValidator(String? value,
    [String? errorMessage]) {
  RegExp regex = CustomRegEx.ssnRegex;
  if (value == null || value.isEmpty) {
    return errorMessage ?? 'Required';
  } else if (value.length != 9) {
    return errorMessage ?? 'Please enter a valid Social Security number';
  } else if (!regex.hasMatch(value)) {
    return errorMessage ?? 'Please enter a valid Social Security number';
  }
  return null;
}