longitudeValidator static method

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

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;
}