ipAddressValidator static method

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

ipAddressValidator to validate an ip address

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

Implementation

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