longitudeValidator static method
longitudeValidator to validate if the provided value matches the pattern of a valid longitude coordinate, ranging from -180 to +180 degrees.
validator: (value) => SimpleValidations.longitudeValidator(value, [errorMessage]),
Implementation
static String? longitudeValidator(String? value, [String? errorMessage]) {
RegExp regex = CustomRegEx.longitudeRegex;
if (value == null || value.isEmpty) {
return errorMessage ?? 'Required';
} else if (!regex.hasMatch(value)) {
return errorMessage ?? 'Please enter a valid longitude';
}
return null;
}