urlValidator static method
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;
}