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

18 lines
414 B
Dart
Raw Normal View History

2020-07-27 20:43:58 +00:00
// Inspired by https://github.com/suragch/string_validator/blob/master/lib/src/validator.dart
final _ipv4 = RegExp(r'^(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)\.(\d?\d?\d)$');
bool ipValidator(str) {
if (str == null) {
return false;
}
if (!_ipv4.hasMatch(str)) {
return false;
}
var parts = str.split('.');
parts.sort((a, b) => int.parse(a) - int.parse(b));
return int.parse(parts[3]) <= 255;
}