Skip to content

Commit

Permalink
fix ipv4_pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifdevil committed Oct 8, 2023
1 parent a2fecbd commit 2c8a525
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public class NetAddressValidatorUtil {

private static final int FIVE = 5;

private static final Pattern IPV4_PATTERN = Pattern.compile("\\d{1,3}(\\.\\d{1,3}){3,5}$");
private static final Pattern IPV4_PATTERN = Pattern
.compile("^" + "(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)" + "(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}" + "$");

private static final Pattern IPV6_STD_PATTERN = Pattern
.compile("^" + "(?:[0-9a-fA-F]{1,4}:){7}" + "[0-9a-fA-F]{1,4}" + "$");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@ public void isIPv6IPv4MappedAddress() {
@Test
public void isIPv4Address() {
assertThat(NetAddressValidatorUtil.isIPv4Address("192.168.1.2")).isTrue();
assertThat(NetAddressValidatorUtil.isIPv4Address("127.0.0.1")).isTrue();
assertThat(NetAddressValidatorUtil.isIPv4Address("999.999.999.999")).isFalse();
}
}

0 comments on commit 2c8a525

Please sign in to comment.