validateZip method
Implementation
String? validateZip(String? value,
{String? requiredError, String? invalidError}) {
if (value == null || value.isEmpty) {
return requiredError ?? 'Please enter a ZIP code';
}
// Regular expression to validate ZIP code format
final zipRegex = RegExp(r'^[0-9]+$');
if (!zipRegex.hasMatch(value)) {
return invalidError ?? 'Please enter a valid ZIP code';
}
return null; // Return null to indicate valid input
}