urlValidator static method

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

urlValidator to validate a URL

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

Implementation

static String? urlValidator(String? value, [String? errorMessage]) {
  RegExp regex = CustomRegEx.urlRegex;
  if (value == null || value.isEmpty) {
    return errorMessage ?? 'Required';
  } else if (!regex.hasMatch(value)) {
    return errorMessage ?? 'Please enter a valid URL';
  }
  return null;
}