3
0
Fork 0
trifid_mobile/lib/validators/ipValidator.dart

27 lines
407 B
Dart
Raw Normal View History

2021-04-23 21:23:06 +00:00
import 'dart:io';
2020-07-27 20:43:58 +00:00
2021-04-23 21:23:06 +00:00
bool ipValidator(String str, bool enableIPV6) {
final ia = InternetAddress.tryParse(str);
if (ia == null) {
2020-07-27 20:43:58 +00:00
return false;
}
2021-04-23 21:23:06 +00:00
switch (ia.type) {
case InternetAddressType.IPv6:
{
if (enableIPV6) {
return true;
}
2021-04-23 21:23:06 +00:00
}
break;
2021-04-23 21:23:06 +00:00
case InternetAddressType.IPv4:
{
return true;
}
break;
2020-07-27 20:43:58 +00:00
}
2021-04-23 21:23:06 +00:00
return false;
2020-07-27 20:43:58 +00:00
}