How can I check if a String is IPv4 / IPv6 or domain name? (Java)

F_Schmidt :

How can I check if a string matches a IPv4, IPv6 adress or a domain name like

I found this for IPv4: Validating IPv4 string in Java And the same kind of system works for IPv6 but how can I check domain names?

EDIT 1: To clarify: I want to check if a string is a valid server address. Valid just means that the FORMAT is correct. The connection will be testet at a different point in the program.

EDIT 2: I will create my own validation method and then post it here

Paul Erlenmeyer :

You do it with regular expressions. You can create a pattern where the first 3 characters are 'w', then a dot, then for example 20 alphanumeric charcacters and so on. After that you check if the given string matches the defined pattern.

The link you provided already uses regular expressions.

Checkout this tutorial on regex in java.

Guess you like